Skip to content

Instantly share code, notes, and snippets.

View JodhwaniMadhur's full-sized avatar
:octocat:
Focusing

Madhur Jodhwani JodhwaniMadhur

:octocat:
Focusing
View GitHub Profile
@JodhwaniMadhur
JodhwaniMadhur / wordLadder.py
Created January 17, 2025 02:16
Word Ladder Solution | BFS | Python
class Solution:
def ladderLength(self, beginWord: str, endWord: str, wordList: List[str]) -> int:
#TC = O(M^2 * N) where M is the length of the words we jump on and N is the length of wordList
#SC = O(M^2 * N) where M is for words we jump on and N is the wordlist space
if endWord not in wordList:
return 0
q = deque([beginWord])
@JodhwaniMadhur
JodhwaniMadhur / mergeSortedLists.cpp
Created January 14, 2025 09:51
Merge K Sorted Lists | C++
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/