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 Stack and Queue Nissan problem solution

YASH PAL, 31 July 202414 February 2026
In this HackerEarth Stack and Queue Nissan problem solution, You are given a stack of N integers such that the first element represents the top of the stack and the last element represents the bottom of the stack. You need to pop at least one element from the stack. At any one moment, you can convert the stack into a queue. The bottom of the stack represents the front of the queue. You cannot convert the queue back into a stack. Your task is to remove exactly K elements such that the sum of the K removed elements is maximized.
 
 
HackerEarth Stack and Queue <Nissan> problem solution

 

 

HackerEarth Stack and Queue Nissan problem solution.

#include <bits/stdc++.h>
#define ll long long
#define MAX 2000000
using namespace std;

int main() {
ll n,k;
cin>>n>>k;
ll arr[n+1];
for(int i=0;i<n;i++) cin>>arr[i];
ll prefix[n+1];
prefix[0]=arr[0];
for(int i=1;i<n;i++) prefix[i]=prefix[i-1]+arr[i];
ll ans=0;
for(int i=0;i<k;i++){
ll temp=prefix[i]+prefix[n-1]-prefix[n-k+i];
ans=max(ans,temp);
}
cout<<ans;

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