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

HackerEarth Fredo is in a Hurry problem solution

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

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programmingoneonone | WordPress Theme by SuperbThemes