We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Combinatorics
  4. Number List
  5. Discussions

Number List

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 16 Discussions, By:

recency

Please Login in order to post a comment

  • shahrierasfak27
    2 years ago+ 0 comments

    include

    using namespace std;

    define ll long long

    define no cout<<"No"<

    define yes cout<<"Yes"<

    define mod 1000000007

    define nt 10 define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

    void solve() { vectorv; sets; mapmp; ll n,m,j,i,y,z,l,r,d,x,k; cin>>n>>k; ll a[n+1]; ll c=0; for(i=0;i>a[i]; if(a[i]>k)c++; } x=0; ll mx=-1,ans=0; for(i=0;ik) { ans+=(i-mx)*(n-i); mx=i; } } cout<

    } int main() { fast; int T=1; cin>>T; while(T--)solve(); return 0; }

    0|
    Permalink
  • Hejo2_71828
    2 years ago+ 0 comments

    Hint: prefix array

    0|
    Permalink
  • akshay_123
    2 years ago+ 0 comments

    Just a humble request to all others who have solved questions like these, please refrain from showing the solutions or giving links to it here in the discussion as it destroys the purpose of solving such problems. Please try to give only intuitions to guide those who need assistance rather than giving them the code.

    Thank you, Sincerely, akshay_123

    3|
    Permalink
  • devinludwig
    4 years ago+ 0 comments

    ruby:

    gets.to_i.times do
        n,k = gets.strip.split.map &:to_i
        a = gets.strip.split.map &:to_i
        max, prev = (1..n).reduce(:+), 0
        for i in 0...n do
            if a[i] > k
                max -= (1..prev).reduce(:+) || 0
                prev = 0
            else
                prev +=1 end
            i += 1 end
        max -= (1..prev).reduce(:+) || 0
        puts max end
    
    0|
    Permalink
  • sumantopal07
    5 years ago+ 0 comments
    for a0 in range(int(input())):
        x=[int(y)for y in input().split()]
        n,k=x[0],x[1]
        ar=[int(y)for y in input().split()]
        s=n
        b=[]
        for i in  range(n):
            if ar[i]>k:
                b.append(s)
            s-=1
        first=0
        if len(b)==0:
            print(0)
            continue
        total=0
        for i in range(n):
            if ar[i]<=k:
                total+=b[first]
            elif ar[i]>k:
                total+=b[first]
                first+=1
                if first==len(b):
                    break
        print(total)
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy