# Leetcode Detailed Solutions

## Leetcode 2: Add Two Numbers

Category: Medium Problem You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. …

## 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 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 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 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 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 1502: Can Make Arithmetic Progression From Sequence

Category: Easy Problem Given an array of numbers arr. A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same. Return true if the array can be rearranged to form an arithmetic progression, otherwise, return false. https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/ Examples Example 1: Example 2: Constraints 2 <= arr.length <= 1000 -10^6 <= arr[i] <= …

## Leetcode 1207: Unique Number of Occurrences

Category: Easy Problem Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique. https://leetcode.com/problems/unique-number-of-occurrences/ Examples: Example 1 Example 2 Example 3 Constraints: 1 <= arr.length <= 1000 -1000 <= arr[i] <= 1000 Solution Approach In this problem, we need to find if …

## Leetcode 728: Self Dividing Numbers

Category: Easy Problem A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0. Also, a self-dividing number is not allowed to contain the digit zero. Given a lower and upper number bound, …

## Leetcode 832: Flipping an Image

Category: Easy Problem Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed.  For example, flipping [1, 1, 0] horizontally results in [0, 1, 1]. To invert an image means that each 0 is replaced by 1, and each 1 is …