Skip to content

Instantly share code, notes, and snippets.

View KeshariPiyush24's full-sized avatar
🏠
Working from home

Piyush Keshari KeshariPiyush24

🏠
Working from home
View GitHub Profile
@KeshariPiyush24
KeshariPiyush24 / Notes.md
Created September 29, 2024 18:40
Sort Stack using Recursion

Sorting a Stack using Recursion

Intuition

The core idea behind sorting a stack using recursion is to:

  1. Remove elements from the stack one by one.
  2. Recursively sort the remaining stack.
  3. Insert the removed element at the correct position in the sorted stack.
@KeshariPiyush24
KeshariPiyush24 / Notes.md
Last active September 29, 2024 18:21
Reverse A Stack Using Recursion

Reversing a Stack using Recursion

Intuition

The core idea behind reversing a stack using recursion is to:

  1. Remove elements from the stack one by one.
  2. Recursively reverse the remaining stack.
  3. Insert the removed element at the bottom of the reversed stack.
@KeshariPiyush24
KeshariPiyush24 / Notes.md
Last active September 23, 2024 06:18
Check Prime or not

Prime Number Testing: Methods, Complexity, and Implementations

1. Basic Concept

A prime number is a natural number greater than 1 that is only divisible by 1 and itself.

2. Efficient Prime Testing Methods

2.1 6k ± 1 Method

@KeshariPiyush24
KeshariPiyush24 / Notes.md
Created September 21, 2024 10:14
349. Intersection of Two Arrays
@KeshariPiyush24
KeshariPiyush24 / Notes.md
Created September 21, 2024 10:06
Row with max 1s

Question: Row with max 1s

Intution: Not exactly binary search but we can utilize the fact that it the row is sorted. We have to use 2 pointers approach.

Time Complexity: $$O(n + m)$$

Space Complexity: $$O(1)$$

Solution:

@KeshariPiyush24
KeshariPiyush24 / Notes.md
Created September 21, 2024 09:36
Frequency In A Sorted Array
@KeshariPiyush24
KeshariPiyush24 / Notes.md
Created September 21, 2024 08:29
Implement Lower Bound

Question: Implement Lower Bound

Intution:

Time Complexity: $$O(log(n))$$

Space Complexity: $$O(1)$$

Solution:

@KeshariPiyush24
KeshariPiyush24 / Notes.md
Last active September 21, 2024 08:27
Implement Upper Bound

Question: Implement Upper Bound

Intution:

Time Complexity: $$O(log(n))$$

Space Complexity: $$O(1)$$

Solution:

@KeshariPiyush24
KeshariPiyush24 / Notes.md
Created September 21, 2024 05:39
153. Find Minimum in Rotated Sorted Array
@KeshariPiyush24
KeshariPiyush24 / Notes.md
Last active September 21, 2024 05:36
367. Valid Perfect Square