All Posts

Leetcode 397: Integer Replacement

Given a positive integer n, you can perform one of the following operations: If n is even, divide n by 2. If n is odd, you can either add 1 to n or subtract 1 from n. Your task is to return the minimum number of operations required to reduce n to 1.

Leetcode 421: Maximum XOR of Two Numbers in an Array

Given an array of integers, your task is to find the maximum result of the XOR operation between any two elements from the array. The goal is to maximize the XOR value of any pair of numbers in the array, where the XOR of two numbers is computed using the bitwise XOR operation.

Leetcode 477: Total Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits differ. Given an integer array nums, return the sum of Hamming distances between all pairs of integers in nums.

Leetcode 638: Shopping Offers

In a store, there are n items available for sale, each with a given price. You are also given a list of special offers where you can buy multiple items at a discounted price. Your task is to determine the minimum total price to purchase the required quantities of each item, while utilizing the special offers optimally. You can use any offer as many times as you like, but cannot buy more items than you need.

Leetcode 645: Set Mismatch

You are given a list of integers that should originally represent all numbers from 1 to n. However, one number appears twice and another number is missing. Your task is to find the number that is duplicated and the one that is missing.

Leetcode 672: Bulb Switcher II

You are in a room with n bulbs, all initially turned on. There are four buttons on the wall, each with a different functionality: flip all bulbs, flip even-numbered bulbs, flip odd-numbered bulbs, and flip bulbs with labels j = 3k + 1. You need to make exactly presses presses. For each press, you can choose any button. Return the number of distinct possible configurations of the bulbs after performing all the presses.