Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

HackerEarth Simon cannot sleep problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes