Parenthesis Checker [ Snapdel – Amazon ]

Problem: Check the balance of parenthesis sequence, the string contains (),{} and []. Link #include <stdio.h> #include <string.h> int main() { //code char s[105]; char arr[105]; int balance; int t,idx,i; scanf("%d",&t); while(t–) { scanf("%s",s); idx=0; balance=1; for(i=0;i<strlen(s);i++) { if(s[i]=='(' || s[i]=='{' || s[i]=='[') arr[idx++]=s[i]; else if(s[i]==')') { if(arr[idx-1]=='(') { idx–; } else balance=0; } else

Find Maximum Distance [ Google-Amazon ]

Problem: An array of integers will be given, find the maximum distance of indexes of  [j – i]  subjected to the constraint of A[i] <= A[j]. A : [4 6 5 3]; Output : 2; For the pair (4, 5). Link #include <stdio.h> int arr[1005]; int t,n,mx; int main() { //code int i,j; scanf("%d",&t); while(t–) { scanf("%d",&n); for(

Removing duplicate chars[Microsoft]

Problem: Given a string, Remove all the duplicate chars, string may include spaces. Solution Hints:solN; ASCII char valaus range from -128 to 127. Link The following solution did not get AC from OJ. My guess is, there may be a problem with that OJ. #include <iostream> #include <string> #include <stdio.h> using namespace std; int main() { //code int

Find Largest Number formed from an Array [PayTm , Amazon]

Problem:A list of non negative integers will be provided, arrange the numbers in such a way that they form the largest number possible. Example: From a list : 9 30 31 4 10 ; Largest number formed : 94313010. Link #include <stdio.h> #include <algorithm> #include <vector> #include <iostream> #include <string> using namespace std; //vector<string> vb; string vb[105]; int n; bool

Inverse Count Of An Array[Microsoft,Flipkart,Amazon]

Problem:How far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Formally speaking, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j. The sequence 2, 4,

Sort a linked list of 0s, 1s and 2s[Microsoft,Amazon]

Problem: Complete the method which takes oneargument: the head ofthe linked list. The programshould not read any input fromstdin/console. The struct Node has a data part which stores the data and a nextpointer which points to the next element of the linked list. There are multiple test cases. For each test case, this method will

Insert an element in a sorted circular linkedList.[Microsoft & Amazon]

Problem:Given a sorted circular linked list, insert a new node so that it remains a sorted circular linked list. Problem Link /* struct node { int data; struct node *next; }; */ void sortedInsert(struct node** head_ref, int x) { node *tmp=(*head_ref); node *prev,*nxt; int val; int start_val=tmp->data; bool first=1; node *p=new node; p->data=x; if(x<tmp->data) {