Coding Interviews

Leetcode 19 Remove Nth Node From End of List

Leetcode 19: Remove Nth Node From End of List

Category: Medium Problem Given the head of a linked list, remove the nth node from the end of the list and return its head. Follow up: Could you do this in one pass? https://leetcode.com/problems/remove-nth-node-from-end-of-list Examples Example 1: Example 2: Example 3: Solution Approach In this problem of “remove nth node from the list”, we are given a linked list whose […]

Leetcode 19: Remove Nth Node From End of List Read More »

169 Majority Element

Leetcode 169: Majority Element

Category: Easy Problem Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the array is non-empty and the majority element always exists in the array. https://leetcode.com/problems/majority-element/description/ Examples Example 1: Example 2: Solution Approach In this problem, we have to find

Leetcode 169: Majority Element Read More »

Valid Sudoku

Leetcode 36: Valid Sudoku

Category: Medium Problem Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition. Note: A Sudoku board (partially filled) could be

Leetcode 36: Valid Sudoku Read More »

Container With Most Water

Leetcode 11: Container With Most Water

Category: Medium Problem Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. Notice that you may not slant the

Leetcode 11: Container With Most Water Read More »

Create Target Array in the Given Order

Leetcode 1389: Create Target Array in the Given Order

Category: Easy Problem Given two arrays of integers nums and index. Your task is to create target array under the following rules: Initially target array is empty. From left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array. Repeat the previous step until there are no elements to read in nums and index. Return the target array. It is guaranteed that the insertion operations will be

Leetcode 1389: Create Target Array in the Given Order Read More »

Leetcode 441: Arranging Coins

Leetcode 441: Arranging Coins

Category: Easy Problem You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number of full staircase rows that can be formed. n is a non-negative integer and fits within the range of a 32-bit signed integer. https://leetcode.com/problems/arranging-coins/ Examples: Example 1 Example 2 Solution

Leetcode 441: Arranging Coins Read More »