Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Fredo is in a Hurry problem solution

YASH PAL, 31 July 202411 February 2026
In this HackerEarth Fredo is in a Hurry problem solution Fredo lives in a building with N + 1 floors and his apartment is at floor N. The floors are numbered from 0 to N, N being the highest floor. Fredo has just come from school and is at floor 0. His favorite anime is about to start and he wants to reach his apartment as soon as possible.
He can either use a staircase or elevator or a combination of both (use staircase for x floors and cover rest floors by elevator) to reach his apartment.
If he uses a staircase, he takes f amount of time to reach floor f from floor f – 1.
An elevator takes 1 unit of time to go from any floor to it’s neighboring floors.
The elevator currently is coming down from floor N .The elevator stops at the floor where the elevator button is pressed .From this floor, the elevator goes to floor N .
Tell him what is the minimum time he needs to reach floor N from floor 0.
HackerEarth Fredo is in a Hurry problem solution

HackerEarth Fredo is in a Hurry problem solution.

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
if(n==1){cout<<"1n";continue;}
ll x=floor((-3.0+sqrt(9.0+8.0*double(n)))/2.0);
cout<<2*(n-x)<<"n";
}
return 0;
}
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 *

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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