Time Stamp - HackerEarth Solution

Time Stamp - HackerEarth Solution

Time Stamp - HackerEarth Solution 

Problem Name - Time Stamp 

Problem Statement

You are given N timestamps. The timestamp is given as HH: MM: SS. The timestamp changes from K or -K seconds.
The negative value of K means K seconds before given timestamp. The timestamp varies from \(0:0:0\) to \(23:59:59\). Once The timestamp reaches \(23:59:59\), it repeats.
Initially, timestamp is \(0:0:0\). There will be no leading zeroes in the input. The timestamp will move K seconds with respect to the previous timestamp.
If timestamp has appeared before then print Yes else print No without quotes.

Example

Consider N = 2, K = [1, 0]:

  • After performing the 1st query. It would become 0:0:1. As it was not appeared before so, the answer would be No.
  • After performing the 2nd query. It would remain 0:0:1. As it was appeared before so, the answer would be Yes.

Function description

Complete the Timestamp function provided in the editor. This function takes the following 2 parameters and returns the array of strings of size N as given in the problem:

  • N: Represents the number of queries.

  • K: An array of size N, represents the time stamp for each query as specified in the problem.

Input format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

  • The first line of input contains the number of queries N.
  • The next line of input contains N space-separated integers denoting the time K in seconds.

Output format
For each query, if timestamp has appeared before then print Yes else print No (without quotes).

Constraints
\(1 \le N \le 10^6\)
\(-10^{18} \le K \le 10^{18}\)

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Time Stamp - HackerEarth Solution

Code -

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod (ll)(24*60*60)
#define sz(a) (ll)a.size()
#define all(aa.begin(),a.end()
#define fr(i,a,bfor(ll i=a;i<b;i++)
#define frr(i,a,bfor(ll i=a-1;i>=b;i--)
#define pb emplace_back
#define ee emplace
#define rr return 0
#define mp make_pair
#define pr  pair <ll,ll>
#define ff first
#define ss second
#define pie 3.1415926535898
#define inf LLONG_MAX
ll mult(ll a,ll bll p=mod){return ((a%p)*(b%p))%p;}
ll add(ll all bll p=mod){return (a%p + b%p)%p;}
ll neg(ll a,ll p=mod){return (p-(a%p))%p;}
ll sub(ll a,ll b,ll p=mod){return add(a,neg(b));}
ll fpow(ll xll y)  
{  
    ll res = 1;     
    x = x % mod; 
    if (x == 0return 0
    while (y > 0)  
    {  
        if (y & 1LL)  
            res = (res*x) % mod;  
        y = y>>1LL;
        x = (x*x) % mod;  
    }  
    return res;  
}  
ll inv(ll all p = mod) {return fpow(a, p - 2);}
bool sa(const pair<ll,ll&a,const pair<ll,ll&b){return (a.second<b.second);}
bool fd(const pair<ll,ll&a,const pair<ll,ll&b){return (a.first>b.first);}
bool sd(const pair<ll,ll&a,const pair<ll,ll&b){return (a.second>b.second);}
ll dx[4]={0,0,1,-1};
ll dy[4]={1,-1,0,0};
bool valid(ll x,ll y,ll n,ll m){
    if(x<0 || y<0){
       return false;
   }
   else if(x>=n || y>=m){
       return false;
   }
   else
   return true;
}
#define maxn 500005 

int main(){
    fio
    ll T;
    T = 1;
    // cin >>T;
    fr(tc,1,T+1){
        // cout<<"Case #"<<tc<<": ";
        ll n,val=0;
        cin>>n;
        assert(1<=n && n<=1000000);
        ll a[n+5];
        fr(i,0,n){
            cin>>a[i];
            assert(-1e18<=a[i] && a[i]<=1e18);
        }
        val=0;
        unordered_map<ll,ll>mpp;
        fr(i,0,n){
            if(a[i]<0){
                a[i]=(-1*a[i]);
                val = sub(val,a[i]);
            }
            else{
                val = add(val,a[i]);
            }
            if(mpp[val]){
                cout<<"Yes\n";
            }
            else{
                cout<<"No\n";
            }
            mpp[val]=1;
        }
    }
    rr;
}

Time Stamp - HackerEarth Solution

Disclaimer: The above Problem is generated by HackerEarth but the Solution is Provided by Us. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website contact us on coderinme.net@gmail.com .

For DMCA: https://allhackerranksolutionsbykaira.blogspot.com/p/dmca.html

Post a Comment

Post a Comment (0)

Previous Post Next Post