Problem:Merge two Sorted (non-increasing) Array. Link #include <stdio.h> void _sort(int ar[],int len1,int br[],int len2) { int i=1,j=1; while(i<=len1 && j<=len2) { if(ar[i]>br[j]) { printf("%d ",ar[i]); i+=1; } else if(ar[i]<br[j]) { printf("%d ",br[j]); j+=1; } else if(ar[i]==br[j]) { printf("%d %d ",ar[i],br[j]); j+=1; i+=1; } } while(i<=len1) printf("%d ",ar[i++]); while(j<=len2) printf("%d ",br[j++]); printf("\n"); } int main() {
Author: Asif Naeem
Find Excel Column Name From Column Number [ Microsoft, Amazon, Samsung ]
Problem:Given a positive integer, return its corresponding column title as appear in an Excel sheet. MS Excel columns has a pattern like A, B, C, … ,Z, AA, AB, AC,…. ,AZ, BA, BB, … ZZ, AAA, AAB ….. etc. In other words, column 1 is named as “A”, column 2 as “B”, column 27 as
Continue Reading “Find Excel Column Name From Column Number [ Microsoft, Amazon, Samsung ]”
Head to Tail ordering
Problem:A head to tail ordering of strings is the one in which the last letter of the previous word is the same as the first letter of the following word. For eg. ‘Angular’can be followed by ‘ rotation’. The task is to write a code to accept a set of finite strings and determine if
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
Continue Reading “Find Largest Number formed from an Array [PayTm , Amazon]”
Pairwise swap elements of a linked list[Amazon – Microsoft – Moonfrog Labs]
Problem:Given a singly linked list, write a function to swap elements pairwise. Link
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,
Continue Reading “Inverse Count Of An Array[Microsoft,Flipkart,Amazon]”
Sort Array Based on Frequency[Oracle]
Problem:Given an array of integers, sort the array according to frequency of elements. For example, if the input array is {2, 3, 2, 4, 5, 12, 2, 3, 3, 3, 12}, then modify the array to {3, 3, 3, 3, 2, 2, 2, 12, 12, 4, 5}. If frequencies of two elements are same, print