All Posts

Leetcode 1642: Furthest Building You Can Reach

You are given an array heights representing the heights of buildings, along with a certain number of bricks and ladders. Your task is to determine the furthest building you can reach by optimally using bricks and ladders.

Leetcode 1646: Get Maximum in Generated Array

Given an integer n, an array nums of length n+1 is generated with the following rules:

  • nums[0] = 0
  • nums[1] = 1
  • nums[2 * i] = nums[i] when 2 <= 2 * i <= n
  • nums[2 * i + 1] = nums[i] + nums[i + 1] when 2 <= 2 * i + 1 <= n

Return the maximum value in the array nums.

Leetcode 1648: Sell Diminishing-Valued Colored Balls

You are given an inventory of different colored balls. The customer wants to buy a specific number of balls, and each ball has a value based on how many of that color are still available. Calculate the maximum total value you can obtain after fulfilling the customer’s order. The result should be returned modulo 10^9 + 7.

Leetcode 1652: Defuse the Bomb

You are given a circular array ‘code’ and an integer ‘k’. To decrypt the code, you must replace every element in the array based on the value of k. If k > 0, replace the i-th element with the sum of the next k elements. If k < 0, replace the i-th element with the sum of the previous k elements. If k == 0, replace the i-th element with 0. The array is circular, meaning the next element of the last one is the first, and the previous element of the first one is the last.

Leetcode 1656: Design an Ordered Stream

You are given a stream of n (id, value) pairs, where id is an integer between 1 and n, and value is a string. The task is to design a stream that returns the values in increasing order of their id. After each insertion, the stream should return the largest possible chunk of values that appear next in the order.

Leetcode 1658: Minimum Operations to Reduce X to Zero

You are given an array of integers nums and an integer x. In each operation, you can either remove the leftmost or rightmost element from the array and subtract its value from x. The task is to determine the minimum number of operations required to reduce x to exactly 0, or return -1 if it’s not possible.