All Posts

Leetcode 2645: Minimum Additions to Make Valid String

Given a string ‘word’ consisting of letters ‘a’, ‘b’, and ‘c’, you can insert letters ‘a’, ‘b’, or ‘c’ anywhere and as many times as needed. Your task is to determine the minimum number of insertions required to transform ‘word’ into a valid string. A string is considered valid if it can be formed by repeatedly concatenating the string ‘abc’.

Leetcode 2656: Maximum Sum With Exactly K Elements

You are given a 0-indexed array of positive integers ’nums’ and an integer ‘k’. You need to perform the following operation exactly k times to maximize your score: Select an element from nums, remove it from the array, and add a new element with a value one greater than the selected element. The score is increased by the value of the selected element. Your task is to return the maximum score you can achieve after performing the operation exactly k times.

Leetcode 2673: Make Costs of Paths Equal in a Binary Tree

You are given a perfect binary tree with n nodes, where each node has a cost associated with it. The tree is numbered from 1 to n, with node 1 as the root. For each node i, its left child is 2*i and its right child is 2*i + 1. You are allowed to increment the cost of any node by 1 any number of times. Your task is to return the minimum number of increments required to make the total cost of the path from the root to each leaf node equal.

Leetcode 2680: Maximum OR

You are given a 0-indexed integer array nums of length n and an integer k. In each operation, you can pick an element from the array and multiply it by 2. Your goal is to determine the maximum possible value of the bitwise OR of all elements in the array after applying the operation at most k times.

Leetcode 2697: Lexicographically Smallest Palindrome

You are given a string s consisting of lowercase English letters. You can perform operations on this string where in each operation, you replace a character in s with another lowercase English letter. The goal is to make s a palindrome using the minimum number of operations possible. If there are multiple ways to achieve the same minimum number of operations, return the lexicographically smallest palindrome string.

Leetcode 2706: Buy Two Chocolates

You are given an integer array representing the prices of chocolates in a store and a total amount of money you have. Your task is to buy exactly two chocolates in a way that ensures you still have some leftover money, and you want to minimize the sum of the prices of the two chocolates. If you cannot buy two chocolates without going into debt, return the original amount of money you had.