Leetcode 206: Reverse Linked List

Problem Statement Description Given the head of a singly linked list, reverse the list, and return the reversed list. Examples Example 1: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Example 2: Input: head = [1,2] Output: [2,1] Example 3: Input: head = [] Output: [] Constraints The number of nodes in the list is the range [0, 5000] -5000 <= Node.val <= 5000 Key Insights In order to reverse a singly linked list iteratively, you need to use three pointers: prev, curr and next....

January 14, 2023 · 3 min · 430 words · Me

Leetcode 409: Longest Palindrome

Problem Statement Description Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, "Aa" is not considered a palindrome here. Examples Example 1: Input: s = "abccccdd" Output: 7 Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7. Example 2: Input: s = "a" Output: 1 Explanation: The longest palindrome that can be built is "a", whose length is 1....

January 14, 2023 · 3 min · 561 words · Me

Leetcode 70: Climbing Stairs

Problem Statement Description You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Examples Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Example 2: Input: n = 3 Output: 3 Explanation: There are three ways to climb to the top....

January 14, 2023 · 6 min · 1163 words · Me

Leetcode 383: Ransom Note

Leetcode Problem Statement Description Given two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise. Each letter in magazine can only be used once in ransomNote. Examples Example 1: Input: ransomNote = "a", magazine = "b" Output: false Example 2: Input: ransomNote = "aa", magazine = "ab" Output: false Example 3: Input: ransomNote = "aa", magazine = "aab" Output: true Constraints 1 <= ransomNote....

January 11, 2023 · 2 min · 384 words · Me

Leetcode 232: Implement Queue Using Stacks

Leetcode Problem Statement Description Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement the MyQueue class: void push(int x) Pushes element x to the back of the queue. int pop() Removes the element from the front of the queue and returns it. int peek() Returns the element at the front of the queue....

January 11, 2023 · 4 min · 757 words · Me