Welcome to my LeetCode practice repository! Here you'll find solutions to various problems from LeetCode, categorized by topic. This repository is meant to serve as a resource for practicing coding skills, particularly in areas such as arrays, graphs, and more.
Arrays are one of the fundamental data structures in computer science. They consist of a collection of elements, each identified by at least one array index or key.
-
Two Sum - Given an array of integers
nums
and an integertarget
, return indices of the two numbers such that they add up totarget
. -
Maximum Subarray - Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
Strings are a sequence of characters, either as a literal constant or as some kind of variable. They are one of the most commonly used data types in programming.
-
Reverse String - Write a function that reverses a string. The input string is given as an array of characters
s
. -
Valid Palindrome - Given a string
s
, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Linked lists are linear data structures where each element is a separate object, called a node, comprising a data and a reference or pointer to the next node in the sequence.
-
Merge Two Sorted Lists - Merge two sorted linked lists and return it as a new sorted list.
-
Linked List Cycle - Given a linked list, determine if it has a cycle in it.
Trees are hierarchical data structures consisting of nodes connected by edges. Each node has a value and a list of references to other nodes.
-
Binary Tree Inorder Traversal - Given the root of a binary tree, return the inorder traversal of its nodes' values.
-
Maximum Depth of Binary Tree - Given a binary tree, find its maximum depth.
Graphs are a set of vertices (nodes) connected by edges. They are used to model pairwise relationships between objects.
-
Number of Islands - Given an
m x n
2D binary gridgrid
which represents a map of'1'
s (land) and'0'
s (water), return the number of islands. -
Course Schedule - There are a total of
numCourses
courses you have to take, labeled from0
tonumCourses - 1
. You are given an arrayprerequisites
whereprerequisites[i] = [ai, bi]
indicates that you must take coursebi
first if you want to take courseai
.
Dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems. It's particularly useful for optimization problems.
-
Climbing Stairs - You are climbing a staircase. It takes
n
steps to reach the top. Each time you can either climb1
or2
steps. In how many distinct ways can you climb to the top? -
Maximum Subarray - Find the contiguous subarray within an array (containing at least one number) which has the largest sum.
This section includes problems that don't fit neatly into the previous categories but are still important for coding interviews and competitive programming.
-
LRU Cache - Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.
-
Median of Two Sorted Arrays - Given two sorted arrays
nums1
andnums2
of sizem
andn
respectively, return the median of the two sorted arrays.
Feel free to explore the solutions and contribute your own! Happy coding!
This template provides a structured overview of common LeetCode topics and links to solutions within the repository. You can further customize it based on your specific needs and preferences.