Practice Program by writing on bare sheet and running it online

 Date: 04 March 2022 

For more program practice, refer my blog Link


Array Programs Collection

  1. Sort an array of 0s, 1s and 2s
  2. Median in a stream of integers (running integers)
  3. Find Second largest element in an array
  4. Find Second largest element in an array
  5. Move all negative elements to end in order with extra space allowed
  6. C++ Program to Rearrange positive and negative numbers in O(n) time and O(1) extra space
  7. Largest Sum Contiguous Subarray
  8. Majority Element
  9. Find the Number Occurring Odd Number of Times
  10. Finding sum of digits of a number until sum becomes single digit
  11. Sliding Window Maximum (Maximum of all subarrays of size k)
Matrix 
Array- Set2
Trickiest Programs

Note:-
If we store keys in binary search tree, a well balanced BST will need time
proportional to M*log N.

Where M is maximum string length
N is numbers of keys in tree

Using Trie, we can search the key in O(M) time.
However penalty is on Trie storage requirement.

Insert and search costs O(key_length), however the memory requirements of Trie is O(ALPHABET_SIZE * key_length * N) where N is number of keys in Trie

Stack Programs

Queue Programs

Linked List Program 

  1. Detect a loop and remove the loop and find the length of the loop
  2. Reverse a linked list
  3. Find the middle of a given linked list
  4. Add two numbers represented by linked lists
  5. Remove duplicates from an unsorted linked list
  6. Swap nodes in a linked list without swapping data
  7. Pairwise swap elements of a given linked list
  8. Move last element to front of a given Linked List
  9. Intersection of two Sorted Linked Lists
  10. Delete a Linked List node at a given position
  11. Function to check if a singly linked list is palindrome
Circular Link list




Advance Programs to practice


Advance Programs to practice
1. Find if two rectangles overlap










(1) Merging of two sorted array

#include<iostream>
using namespace std;

void mergeArrays(int a[], int b[], int size1, int size2)
{
    int size = size1 + size2;
    int c[size] = {0};
    int j =0;
    int k =0;
    int i =0;
    while(i<size1 &&j<size2)
    {
        if (a[i]<b[j])
        {
            c[k] = a[i];
            cout<<"testing1:"<<a[i]<<endl;
            i++; k++;
            
        }
        else if (a[i]>b[j])
        {
            c[k] = b[j];
            cout<<"testing2:"<<a[j]<<endl;
            j++; k++;
            
        }
        else
        {
            c[k] = a[i];
            k++;i++;
            c[k] = b[j];
            k++;j++;
        }
    }
    for(int k =0;k<size;k++)
    {
        cout<<c[k]<<" ";
    }
    
}

int main()
{
    int a[] = {1, 3, 5, 7,9}, b[] = {2, 4, 6, 8, 9};
     
    int size = sizeof(a)/sizeof(int);
    int size1 = sizeof(b)/sizeof(int);
     
    // Function call
    mergeArrays(a, b, size, size1);
     
    return 0;
}

Comments

Popular posts from this blog

Design Pattern and Architecture in C++

Google Test (gtest) Notes

Stack & Queue interview Questions