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
- Sort an array of 0s, 1s and 2s
- Median in a stream of integers (running integers)
- Find Second largest element in an array
- Find Second largest element in an array
- Move all negative elements to end in order with extra space allowed
- C++ Program to Rearrange positive and negative numbers in O(n) time and O(1) extra space
- Largest Sum Contiguous Subarray
- Majority Element
- Find the Number Occurring Odd Number of Times
- Finding sum of digits of a number until sum becomes single digit
- Sliding Window Maximum (Maximum of all subarrays of size k)
Matrix
Array- Set2
Trickiest Programs
- Next greater element in same order as input
- Next Greater Element
- Next Smallest element
- The Celebrity Problem
- Find minimum difference between any two elements
- Size of The Subarray With Maximum Sum
- Merge two sorted arrays with O(1) extra space
String Programs
Note:-
If we store keys in binary search tree, a well balanced BST will need timeproportional 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
- Detect a loop and remove the loop and find the length of the loop
- Reverse a linked list
- Find the middle of a given linked list
- Add two numbers represented by linked lists
- Remove duplicates from an unsorted linked list
- Swap nodes in a linked list without swapping data
- Pairwise swap elements of a given linked list
- Move last element to front of a given Linked List
- Intersection of two Sorted Linked Lists
- Delete a Linked List node at a given position
- Function to check if a singly linked list is palindrome
Circular Link list
Binary Search Tree
- Find the node with minimum value in a Binary Search Tree
- Find the node with minimum value using recursion
- Insert a new node in BST
- Program for inorder traversal in BST
- A program to check if a binary tree is BST or not
- Check if a binary tree is subtree of another binary tree
- Height of binary search tree
- How to determine if a binary tree is height-balanced?
- Print Left View of a Binary Tree
- Print Right View of a Binary Tree
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
Post a Comment