Skip to content

khaled308/dsa

Repository files navigation

DSA

Pattern

  • print triangle pattern
  • print diamond pattern
  • print hollow square pattern
  • print reverse triangle pattern
  • print pyramid pattern

Array

  • max element in array
  • second max element in array
  • check if array is sorted
  • count number of elements that have at least one element greater than itself
  • find unique element in array
  • find missing number in array
  • max sum of sub array
  • print all sub arrays
  • Remove Duplicates from Sorted Array
  • move all zeros to end of array
  • find sub array with given sum
  • rotate array by one
  • rotate array by given number
  • leaders in array (question: 16 17 4 3 5 2, answer: 17 5 2)
  • maximum difference between two elements in array such that larger element appears after smaller element
  • stock buy sell to maximize profit
  • max consecutive ones in binary array
  • maximum length even odd sub array
  • equilibrium index
  • find a sub array of size k with the least average
  • 3 sum

Math

  • sum of digits of a number
  • power of a number
  • fibonacci series
  • armstrong number (question: 153 = 1^3 + 5^3 + 3^3)
  • print all divisors of a number
  • GCD of two numbers
  • count number of digits in a number
  • check if a number is prime or not
  • check if a number is palindrome or not
  • count trailing zeros in factorial of a number

Matrix

  • matrix row sum
  • matrix column sum
  • rotate matrix by 90 degree

Stack

  • Stack implementation using array
  • reverse a string using stack
  • parenthesis matching using stack

Queue

  • Queue implementation using array

Searching

  • linear search
  • binary search
  • square root of a number
  • return indices of two numbers whose sum is equal to given number
  • find first and last occurrence of a number in sorted array
  • search in rotated sorted array
  • count number of occurrences in sorted array
  • search in infinite sorted array

Bit Manipulation

  • given a number, set its i'th bit
  • given a number, clear its i'th bit
  • given a number, toggle its i'th bit
  • given a number, check if its i'th bit is set or not
  • given a number, count number of set bits
  • given array of numbers, every number occurs twice except one, find that number

Sorting

  • bubble sort
  • selection sort
  • insertion sort
  • merge sort
  • quick sort
  • Problems:

    • merge Two sorted array
    • intersection of two sorted array
    • union of two sorted array

String

Recursion

  • print numbers from n to 1
  • print numbers from 1 to n
  • power of a number
  • print binary form of a number
  • reverse a string
  • array sum using recursion
  • flatten array using recursion
  • string palindrome using recursion
  • string permutation
  • array permutation
  • Given m, n count number of ways to reach from (0, 0) to (m, n) in a matrix
  • letter combination of a phone number
  • find the first index if element in array or -1 if not present
  • find the last index if element in array or -1 if not present
  • get all subsequences of a string
  • generate parenthesis
  • decode ways
  • given a rope of length n, find the maximum number of pieces you can make such that the length of each piece is in set {a, b, c}
  • maxPieces
  • tower of hanoi
  • K-th Symbol in Grammar
  • Find the Winner of the Circular Game

hashing

Linked List

  • Singly Linked List implementation
  • Doubly Linked List implementation
  • Circular Linked List implementation

Binary Search Tree

  • insert node in BST
  • in order traversal
  • pre order traversal
  • post order traversal
  • level order traversal
  • search node in BST
  • height of BST
  • balanced BST

backtracking

  • string permutation
  • Maximum Length of a Concatenated String with Unique Characters

Dynamic Programming

Two Pointer

  • pair of elements in sorted array whose sum is equal to given number
  • count number of connective numbers that equal to num
  • sort array of 0s & 1s