Category : cp

I want to compute Kth Smallest Element of of A[i]+A[j] (1<i<j<n), but I am getting memory limit exceed for this given problem , how can I overcome this ? Input: The first line of the input contains – the size of the array and . Second-line integers elemnets of array #include<bits/stdc++.h> using namespace std; #define ..

Read more

https://www.hackerrank.com/challenges/balanced-brackets/problem This is the question link and here is my code : #include <bits/stdc++.h> using namespace std; // Complete the isBalanced function below. string isBalanced(string s) { stack<char> st; for(int i=0;i<(int)s.size();i++) { switch(s[i]) { case ‘(‘ : case ‘{‘ : case ‘[‘ : st.push(s[i]); break; case ‘)’ : **if(st.top()!='(‘ || st.empty())** { return "NO"; } ..

Read more

Following is the code which is running as expected in local ide but when i am submitingh the code in codeforces it is displaying that the outputs are wrong.Question is enter link description heredense array #include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t–) { std::vector<int> my; int x,i,a,j,bno,sno; cin>>x;//enter number of elements ..

Read more

Problem There are N soldiers located on our X-AXIS. The point at which soldier is located also has some number of bombs. The war is near and every soldier wants to communicate with every other soldier. If the ith soldier has b number of bombs and is located at position X then the cost of ..

Read more

I execute the below program on the custom test cases, And it successfully passed the test cases. But while submitting it gives Runtime error: SIGTSTP. #include <bits/stdc++.h> #include<vector> using namespace std; int solve(int arr[], int &n){ int count=1; if(n==1) return count; for(int i=1; i<n; i++){ if(arr[i]<=arr[i-1]){ count++; } } return count; } int main(){ int ..

Read more