Skip to content

Indecre/DSA-catalog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 

Repository files navigation

πŸ“˜ DSA Journey Catalog

Welcome to my DSA (Data Structures and Algorithms) journey! This repository is a personal log of the concepts I’ve learned, problems I’ve solved, and progress I’ve made while mastering DSA. It serves both as a revision notebook and a motivation tracker.


πŸ—“οΈ Progress Tracker


πŸ“… Day 1

  • Topics Covered:
    • Binary Search
    • Pivot in Array
  • βœ… Approach: Binary search for arr[mid] < arr[mid+1] to locate the increasing slope end.
  • πŸ’‘ Method Used: peakIndexInMountainArray(vector<int>& arr)
  • πŸ’» C++ Snippet:
while (low < high) {
    int mid = low + (high - low) / 2;
    if (arr[mid] < arr[mid + 1]) low = mid + 1;
    else high = mid;
}
  • βœ… Approach: Two binary searches: one for the first and one for the last occurrence.
  • πŸ’‘ Method Used: searchRange(vector<int>& nums, int target)
  • πŸ’» C++ Snippet:
int binarySearch(bool findFirst) {
    int res = -1;
    while (low <= high) {
        int mid = (low + high) / 2;
        if (nums[mid] == target) {
            res = mid;
            findFirst ? high = mid - 1 : low = mid + 1;
        }
        else if (nums[mid] < target) low = mid + 1;
        else high = mid - 1;
    }
    return res;
}

πŸ“… Day 2

  • Topics Covered:
    • Binary Search Applications
  • βœ… Approach: Modified binary search using pivot logic.
  • πŸ’‘ Method Used: search(vector<int>& nums, int target)
  • βœ… Approach: Binary search between 1 and x/2, compare mid*mid.
  • πŸ’‘ Method Used: mySqrt(int x)

πŸ“… Day 3

  • Topics Covered:
    • Strings
    • String Arrays
  • βœ… Approach: Two pointers from both ends, skip non-alphanumerics.
  • βœ… Approach: Trim + reverse each word + reverse entire string.

πŸ“… Day 4

  • Topics Covered:
    • Strings
    • Sliding Window
  • βœ… Approach: Sliding window to compare substring matches.
  • βœ… Approach: Compare frequency maps of sliding window and target.
  • βœ… Approach: Use two pointers to modify array in-place.

πŸ“… Day 5

  • Topics Covered:
    • 2D Arrays

1. Wave Print of a 2D Matrix

  • βœ… Approach: Traverse columns alternatively top to bottom and bottom to top.

2. Spiral Print of a 2D Matrix

  • βœ… Approach: Maintain 4 boundaries and iterate in spiral fashion.

πŸ“… Day 6

  • Topics Covered:
    • 2D Arrays
  • βœ… Approach: Flatten the matrix logically and apply binary search.
  • βœ… Approach: Start from top-right, eliminate row or column based on comparison.

πŸ“… Day 7

  • Topics Covered:
    • Recursion
  • βœ… Approach: Pop elements recursively and insert them back in sorted order.
  • πŸ’» C++ Snippet:
void insert(vector<int>& arr, int temp) {
    if (arr.empty() || arr.back() <= temp) {
        arr.push_back(temp);
        return;
    }
    int val = arr.back(); arr.pop_back();
    insert(arr, temp);
    arr.push_back(val);
}

πŸ“… Day 8

  • Topics Covered:
    • Recursion
  • βœ… Approach: Base case and recursive reduction of search space.

πŸ“… Day 9

  • Topics Covered:
    • Recursion
  • βœ… Approach: Backtracking to include/exclude elements.
  • βœ… Approach: Same as Subsets but skip duplicates using sorted array.

πŸ“… Day 10

  • Topics Covered:
    • Recursion
  • βœ… Approach: Map each digit to possible characters and recurse to build combinations.
  • πŸ’» C++ Snippet:
void backtrack(string& digits, int index, string& path, vector<string>& res, vector<string>& map) {
    if (index == digits.size()) {
        res.push_back(path);
        return;
    }
    for (char c : map[digits[index] - '0']) {
        path.push_back(c);
        backtrack(digits, index + 1, path, res, map);
        path.pop_back();
    }
}

πŸ“… Day 11

  • Topics Covered:
    • Linked List
  • βœ… Approach: Iteratively reverse the pointers using three variables.
  • πŸ’» C++ Snippet:
ListNode* reverseList(ListNode* head) {
    ListNode* prev = nullptr;
    while (head) {
        ListNode* next = head->next;
        head->next = prev;
        prev = head;
        head = next;
    }
    return prev;
}

πŸ“… Day 11

  • Topics Covered:
    • Linked List
  • βœ… Approach: Reverse the part of linked list which from left to right and then connect the reversed linked list to the res of the elements. i.e left to prevright-> and right to x where x -> next = prevleft
  • πŸ’» C++ Snippet:
class Solution {
public:
    ListNode* reverseBetween(ListNode* head, int left, int right) {
        if (!head || left == right) return head;

        // Create a dummy node to simplify edge cases
        ListNode* dummy = new ListNode(0);
        dummy->next = head;

        // Step 1: Move to node before 'left'
        ListNode* prevLeft = dummy;
        for (int i = 1; i < left; ++i) {
            prevLeft = prevLeft->next;
        }

        // Step 2: Reverse from left to right
        ListNode* curr = prevLeft->next;      // Node at 'left'
        ListNode* prev = nullptr;
        ListNode* tail = curr;                // This will become the tail after reversing

        for (int i = 0; i < right - left + 1; ++i) {
            ListNode* nextTemp = curr->next;
            curr->next = prev;
            prev = curr;
            curr = nextTemp;
        }

        // Step 3: Connect reversed part with remaining list
        prevLeft->next = prev;    // 'prev' is new head of reversed sublist
        tail->next = curr;        // 'curr' is the node after 'right'

        return dummy->next;
    }
};

🎯 Goal

To build a strong foundation in core DSA concepts and solve a wide range of problems with increasing difficulty, preparing for technical interviews and competitive programming.


πŸ› οΈ Tools Used


πŸš€ How to Use

Feel free to explore the daily logs, code snippets, and approaches. You can fork this repository and start your own DSA journey too!


πŸ™Œ Let’s Connect!

If you're also on your DSA journey, let’s connect and grow together!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors