LeetCode - Blind 75 - Sum of Two Integers

The problem Given two integers a and b, return the sum of the two integers without using the operators + and -. Examples Input: a = 1, b = 2 Output: 3 Input: a = 2, b = 3 Output: 5 Constraints -1000 <= a, b <= 1000 Explanation From the description of the problem, we learn that we need to figure out the way of adding two numbers without using + or - operators. Let’s visualize this problem and find the way we can do it. ...

May 14, 2025 · 3 min · Dmytro Chumakov

LeetCode - Blind 75 - Missing Number

The problem Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Examples Input: nums = [3,0,1] Output: 2 Explanation: n = 3 since there are 3 numbers, so all numbers are in the range [0,3]. 2 is the missing number in the range since it does not appear in nums. Input: nums = [0,1] Output: 2 Explanation: n = 2 since there are 2 numbers, so all numbers are in the range [0,2]. 2 is the missing number in the range since it does not appear in nums. Input: nums = [9,6,4,2,3,5,7,0,1] Output: 8 Explanation: n = 9 since there are 9 numbers, so all numbers are in the range [0,9]. 8 is the missing number in the range since it does not appear in nums. Constraints n == nums.length 1 <= n <= 10^4 0 <= nums[i] <= n All the numbers of nums are unique. Follow up: Could you implement a solution using only O(1) extra space complexity and O(n) runtime complexity? ...

May 12, 2025 · 4 min · Dmytro Chumakov

LeetCode - Blind 75 - Reverse Bits

The problem Reverse bits of a given 32-bit unsigned integer. Note: Note that in some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer’s internal binary representation is the same, whether it is signed or unsigned. In Java, the compiler represents the signed integers using 2’s complement notation. Therefore, in Example 2 above, the input represents the signed integer -3 and the output represents the signed integer -1073741825. Examples Input: n = 00000010100101000001111010011100 Output: 964176192 (00111001011110000010100101000000) Explanation: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192, whose binary representation is 00111001011110000010100101000000. Input: n = 11111111111111111111111111111101 Output: 3221225471 (10111111111111111111111111111111) Explanation: The input binary string 11111111111111111111111111111101 represents the unsigned integer 4294967293, so return 3221225471, whose binary representation is 10111111111111111111111111111111. Constraints The input must be a binary string of length 32 Follow up: If this function is called many times, how would you optimize it? ...

May 10, 2025 · 4 min · Dmytro Chumakov

LeetCode - Blind 75 - Counting Bits

The problem Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1s in the binary representation of i. Examples Input: n = 2 Output: [0,1,1] Explanation: 0 --> 0 1 --> 1 2 --> 10 Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 --> 0 1 --> 1 2 --> 10 3 --> 11 4 --> 100 5 --> 101 Constraints 0 <= n <= 10^5 Follow up: ...

May 8, 2025 · 5 min · Dmytro Chumakov

LeetCode - Blind 75 - Number of 1 Bits

The problem Given a positive integer n, write a function that returns the number of set bits in its binary representation (also known as the Hamming weight). A set bit refers to a bit in the binary representation of a number that has a value of 1. Examples Input: n = 11 Output: 3 Explanation: The input binary string 1011 has a total of three set bits. Input: n = 128 Output: 1 Explanation: The input binary string 10000000 has a total of one set bit. Input: n = 2147483645 Output: 30 Explanation: The input binary string 1111111111111111111111111111101 has a total of thirty set bits. Constraints 1 <= n <= 2^31 - 1 Follow up: If this function is called many times, how would you optimize it? ...

May 5, 2025 · 3 min · Dmytro Chumakov