Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Sherlock and Date problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Sherlock and Date problem solution Watson gives a date to Sherlock and asks him what is the date on the previous day. Help Sherlock. You are given a date in DD MM YYYY format. DD is an integer without leading zeroes.
 
MM is one of the “January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November” and “December” (all quotes for clarity). YYYY is also an integer between 1600 and 2000 without leading zeroes. You have to print the date of the previous day in the same format.
 
 
HackerEarth Sherlock and Date problem solution

 

 

HackerEarth Sherlock and Date problem solution.

import datetime
from datetime import date, timedelta


n = int(raw_input())

while n>0 :
date = raw_input();
day , month ,year = date.split();
assert(int(day)>0 & int(day)<31)
#print(day+" "+month+" "+year)
map = {
'January':1,
'February':2,
'March':3,
'April':4,
'May':5,
'June':6,
'July':7,
'August':8,
'September':9,
'October':10,
'November':11,
'December':12
}

mlist = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
]

mydate = (datetime.date(int(year),map[month],int(day))) #year, month, day
#mydate =mydate+datetime.timedelta(years=40)
mydate= mydate-datetime.timedelta(days=1)
mydate = mydate.isoformat();
#print(mydate)
year ,month,day = mydate.split('-')
#print(year+" "+month+" "+day)
#print(mydate.strftime("%Y-%m-%d"))
#year = mydate.strftime("%Y");
if(int(month)<10):
month = month.strip("0");
#day = mydate.strftime("%d");
if(int(day)<10):
day = day.strip("0")
#print(month);
print(day+" "+mlist[int(month)-1] +" "+year)
n=n-1
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes