GithubHelp home page GithubHelp logo

sankalpdayal5 / leetcode-solutions Goto Github PK

View Code? Open in Web Editor NEW
11.0 2.0 27.0 191 KB

:octocat: (Daily Update) Java / Python Solutions of LeetCode Problems

Home Page: https://www.youtube.com/c/sankalpdayal5

License: Apache License 2.0

Java 54.68% Python 33.52% C++ 11.80%
leetcode leetcode-solutions leetcode-java leetcode-python algorithms data-structures data-structure java python python3

leetcode-solutions's Introduction

LeetCode Solutions

Find video link at my YouTube channel
Or from the Sheet 1 of this Google Sheet

Made with Python Made with Java Made with C++

# Title Solution Code Time Space Difficulty Tags Video
0001 2 Sum problem Check all the combinations by looping Map, if itโ€™s complement (target - element) and exists then return the indices of the current element and the complement. C++ Java Python O(n) O(1) Easy Hash Table Heap ๐Ÿ“บ
0011 Container With Most Water Two pointer approach from left and right side. Increment the left pointer if height is less than right otherwise decrement the right pointer. If current holding capacity is more than previous update. Python O(n) O(1) Medium Array Two pointer
0021 Merge Two Sorted Lists Algo The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy. The dummy node gives the tail something to point to initially when the result list is empty. C++ O(m+n) O(1) Easy Linked List ๐Ÿ“บ
0021 Merge Two Sorted Lists The strategy here uses a temporary dummy node as the start of the result list. The pointer Tail always points to the last node in the result list, so appending new nodes is easy.The dummy node gives the tail something to point to initially when the result list is empty.This dummy node is efficient, since it is only temporary, and it is allocated in the stack.The loop proceeds, removing one node from either โ€˜aโ€™ or โ€˜bโ€™, and adding it to the tail Java O(n) O(1) Easy Linked List ๐Ÿ“บ
0027 Remove Element Two pointers for counting valid nos and swapping Java Python O(n) O(1) Easy Array Two Pointers ๐Ÿ“บ
0044 Wildcard Matching Use bottom-up approach, when '?' detected copy value from upper diagonal cell and when '*' detected copy value from previous coloumn same row or previous row same coloumn Python O(n*n) O(n*n) Hard DP on Regex problem
0045 Jump Game II newEnd = max(newEnd, i+nums[i]) C++ O(n) O(1) Hard Array Greedy ๐Ÿ“บ
0053 Maximum Subarray Parse array and save the best solution at each step Java Python O(n) O(1) Easy Array Dynamic Programming ๐Ÿ“บ
0055 Jump Game Iterate from last index and check if we can reach there from current index or not Python O(n) O(1) Medium Array Greedy ๐Ÿ“บ
0062 Unique Paths (Total no of unique paths in m x n matrix) As the first element in each row will always be 1, so maintaining one row is enough to reach bottom-right corner of the grid Java Python O(n) O(1) Medium Array Dynamic Programming
0070 Climbing Stairs steps[n]=steps[n-1]+steps[n-2]. C++ Python O(n) O(1) Easy Dynamic Programming ๐Ÿ“บ
0072 Edit Distance minDis(i,j)=min(minDis(i-1,j),minDis(i,j-1),minDis(i-1,j-1))+1; Java O(m*n) O(m*n) Hard String Dynamic programming
0073 Set Matrix Zeroes Use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. C++ Python O(m*n) O(1) Medium Array ๐Ÿ“บ
0075 Sort an array of 0โ€™s 1โ€™s 2โ€™s without using extra space or sorting algo the logic is to count total number of 0's, 1's and 2's int the list and starting from beginning first append total 0's then total 1's and then 2's Java Python O(n) O(1) Medium Array ๐Ÿ“บ
0100 Same Tree Check isSame(node.left) and isSame(root.right) Java O(n) O(h) Easy Tree Depth-first-Search ๐Ÿ“บ
0100 Same Tree Check isSame(node.left) and isSame(root.right) Java Python O(n) O(h) Easy Tree Depth-first-Search ๐Ÿ“บ
0101 Symmetric Tree Check if left.left==right.right and left.right==right.left Java Python O(n) O(h) Easy Tree Depth-first-Search Breadth-first-Search ๐Ÿ“บ
0104 Maximum Depth of Binary Tree Depth = 1 + Max(depth of left, depth of right) Java O(n) O(h) Easy Tree Depth-first-Search ๐Ÿ“บ
0121 Best time to buy and sell stock Minimize Cost price and Maximise Profit , if the current value minus the minimum is the new maximum profit Java Python O(n) O(1) Easy Array Dynamic Programming ๐Ÿ“บ
0142 Linked List Cycle II Floydโ€™s Cycle detection algorithm Java O(n) O(1) Medium Linked List Two pointers
0198 House Robber Keep track of max money by figuring out whether to loot the current house or not Python O(n) O(1) Easy Dynamic Programming ๐Ÿ“บ
0200 Number of islands Merging adjacent lands, and the merging is done recursively Java O(nโˆ—m) O(1) Medium Depth-First Search Breadth-First Search ๐Ÿ“บ
0268 Missing Number Assuming that XOR is a constant-time operation, this algorithm does constant work on nn iterations, so the runtime is overall linear C++ Java O(n) O(1) Easy Array Math BitManipulation
0283 Move Zeroes Two pointers for counting valid nos and swapping Java O(n) O(1) Easy Array Two Pointers ๐Ÿ“บ
0287 Find duplicate in array of N+1 numbers Find the cycle using slow and fast pointer Java O(n) O(1) Medium Array Two Pointers
0300 Longest Increasing Subsequence when next element in array is greater than previous element, dp[i]=maximum(dp[j]+1,dp[i]) Java O(n*m) O(n) Medium Binary Search Dynamic Programming
0451 Sort Characters By Frequency LeetCode Github Java Python O(n) O(n) Medium Hash Table Heap
0509 Fibonacci Number Storing the value of two previous number and updating them Java O(n) O(1) Easy Array ๐Ÿ“บ
0647 Palindromic Substrings Extend from center, 2 function call for odd and even palindromes Java Python O(n^2) O(1) Medium String Dynamic Programming ๐Ÿ“บ
0695 Max Area of Island Apply DFS on the Gird by exploring every square connected to it 4-directionally, total number of squares explored will be the area of that connected shape. C++ O(Rโˆ—C) O(Rโˆ—C) Medium Depth-First-Search
0876 Middle of the Linked List Find the length of given linked list and then traverse from root till one less than half of linked list length and print the next node to current node Java O(n) O(1) Easy Linked List
0983 Minimum Cost For Tickets Here dp(i) is the cost to travel from day days[i] to the end of the plan. if days[j] < days[i] + 1 then j1=j. if days[j] < days[i] + 7 then j=j7. if days[j] < days[i] + 30 then j=j30 . dp(i)=min(dp(j1)+costs[0],dp(j7)+costs[1],dp(j30)+costs[2]) Java O(n) O(n) Medium Dynamic Programming ๐Ÿ“บ
1347 Minimum Number of Steps to Make Two Strings Anagram Add 1 for char in s and remove 1 for char in t Java Python O(n+m) O(1) Medium Hash Table Heap ๐Ÿ“บ
1352 Product of the Last K Numbers Add new element to list by multiplying it with previous number and return arr[n-1]/arr[n-k-1] Python O(1) O(1) Medium Array Design ๐Ÿ“บ

Format

0000 Ques name Algo Java O() O() Easy Category ๐Ÿ“บ
0000 Ques name Algo Java O() O() Easy Category ๐Ÿ“บ

Built with love

leetcode-solutions's People

Contributors

99ansh avatar aayush1607 avatar amulya12 avatar anuj840 avatar aryan-mehta avatar chaitanyadave23 avatar codejayant avatar coderj001 avatar crjain avatar darshita-kumar avatar hacktober2020 avatar hemant0011 avatar jevin925 avatar oudarjya718 avatar rahulg606 avatar sankalpdayal5 avatar sanyapandey-hub avatar srishtisingh-hub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

leetcode-solutions's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.