Problem : https://www.hackerrank.com/challenges/cpp-maps/problem
Solution :
Problem : https://www.hackerrank.com/challenges/cpp-maps/problem
Solution :
Problem : https://www.hackerrank.com/challenges/c-tutorial-stringstream/problem
Solution :
#include <sstream>
Solution :
#include <stdio.h>
#include<math.h>
void update(int *pa,int *pb) {
// Complete this function
int temp = *pa;
*pa = *pa + *pb;
*pb = abs(temp - *pb);
}
int main() {
int a, b;
int *pa = &a, *pb = &b;
scanf("%d %d", &a, &b);
update(pa, pb);
printf("%d\n%d", a, b);
return 0;
}
#include<iostream>
#include<stack>
using namespace std;
stack<int>s1;
stack<int>s2;
void push(int element){
s1.push(element);
}
int pop(){
if(!s2.empty()){
int r = s2.top();
s2.pop();
return r;
}else{
while(!s1.empty()){
int t = s1.top();
s1.pop();
s2.push(t);
}
int r = s2.top();
s2.pop();
return r;
}
}
int main(){
// s1 and s2
//push : 1 2 3 4
//pop : -> 1
//push : 5 -> 2 3 4 5
//pop : -> 2
push(1);
push(2);
push(3);
push(4);
cout<<pop();
push(5);
cout<<'\n'<<pop();
return 0;}
NOTE : Write code for queue properties and even do check for empty before popping the element from the queue ...