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 Simon cannot sleep problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Simon cannot sleep problem solution It’s 12 o’clock at midnight (00 : 00) and Simon cannot sleep! So he decided to stare at the clock on his wall until he falls asleep.
 
He saw the clock’s hands and got to thinking ‘How many times they’ll pass each other until I fall asleep’ hh : mm. Imagine that he fell asleep at . Now, you must figure out how many times clock’s hands overlap from 00 : 00 to hh : mm (including 00 : 00 and hh : mm).
 
hackerEarth Simon cannot sleep problem solution
 

hackerEarth Simon cannot sleep problem solution.


#include <bits/stdc++.h>

using namespace std;

int h, m;
char c;

int moji(int h, int m){
int p = m / 5;
int ans = h;
if(h >= 12)
h -= 12, ans--;
if(p > h) ans++;
else if (p == h){
if(m % 5 >= m / 12.0)
ans++;
}
return ans;
}

int ali(int h, int m){
int ans = h;
if(h >= 12)
h -= 12, ans--;
return ans + (11 * m >= h * 60);
}

int main(){
cin >> h >> c >> m;
cout << moji(h, m) << endl;

return 0;
}

second solution

h, m = map(int, input().split(':'))

print((m * 12 >= h % 12 * 60 + m) + (h if h < 12 else h - 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