Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth 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 *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

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