Posts

Linked List 10 operations from which problems are made ( complete guide for you)

/* These are the functions we will implement make your seatbelts tight and start progrmming cout<<" 1. Insert node at begining"<<endl; cout<<" 2. Append a node"<<endl; cout<<" 3. display the l.l"<<endl; cout<<" 4. Insert before a selected node"<<endl; cout<<" 5. Insert after a selected node "<<endl; cout<<" 6.Delete a particular node"<<endl; cout<<" 7.Reverse A L.L "<<endl; cout<<" 8. Do bot reverse the l.l but display the reversed order (using recursion)"<<endl; cout<<"9. find middle element in a list using slow and fast pointer"<<endl; cout<<"10. check if linked list is palindrome or not (we know if even f=NULL odd f->next=NULL)"<<endl; cout<<" 11. exit"<<endl; */ #include<iostream> using namespace std; struct node{

Intro to Hashing problems made easy

/*--- Below are 3 problems i have used hasing technique, After seeing below problems you'll be 100% clear on the basic hasing needed for competative programming First Repeating Element  Given an array arr[] of size N. The task is to find the first repeating element in an array of integers, i.e., an element that occurs more than once and whose index of first occurrence is smallest. Input : The first line contains an integer T denoting the total number of test cases. In each test cases, First line is number of elements in array N and second its values. Output: In each separate line print the index of first repeating element, if there is not any repeating element then print “-1” (without quotes). Use 1 Based Indexing. Constraints: 1 <= T <= 500 1 <= N <= 106 0 <= Ai <= 106 Example: Input: 1 7 1 5 3 4 3 5 6 Output: 2 Explanation: Testcase 1: 5 is appearing twice and its first appearence is at index 2 which is less than 3 whose first occur

Codechef Operations in a matrix

/* Sakshi had a matrix with  N N  rows (numbered  1 1  through  N N ) and  M M  columns (numbered  1 1  through  M M ). Initially, all cells of this matrix contained  0 0 -s. Let's denote a cell in row  r r  and column  c c  by  ( r , c ) ( r , c ) . Sakshi is well-known for troubling others. This time, her friends Nikki and Mansi planned to take revenge and teach her a lesson, so they changed her matrix by performing the following operation  Q Q  times: Choose any valid cell  ( x , y ) ( x , y ) . Add  1 1  to all the cells in row  x x . Add  1 1  to all the cells in column  y y . For each valid  i i , the cell chosen in the  i i -th operation was  ( X i , Y i ) ( X i , Y i ) . Nikki and Mansi challenged Sakshi to find the number of cells in the resulting matrix which contain odd integers. Sakshi is not good at math, since she has spent all her life troubling others, so this time, she really needs your help. Help Sakshi find the answer. Input The first line of the