[CODING] Maximum Total Beauty of the Gardens solution leetcode

Alice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens. Maximum Total Beauty of the Gardens solution leetcode You are given a 0-indexed integer array flowers of size n, where flowers[i] is the number of flowers already planted in the ith garden. Flowers that are already planted cannot be removed. You are then given another integer newFlowers, … Read more

[CODING] Maximum Product After K Increments solution leetcode

Maximum Product After K Increments solution leetcode Return the maximum product of nums after at most k operations. Since the answer may be very large, return it modulo 109 + 7.   Example 1: Input: nums = [0,4], k = 5 Output: 20 Explanation: Increment the first number 5 times. Now nums = [5, 4], with a product of 5 * 4 = 20. It can be shown … Read more

[CODING] Minimize Result by Adding Parentheses to Expression solution leetcode

Minimize Result by Adding Parentheses to Expression solution leetcode Add a pair of parentheses to expression such that after the addition of parentheses, expression is a valid mathematical expression and evaluates to the smallest possible value. The left parenthesis must be added to the left of ‘+’ and the right parenthesis must be added to the right of ‘+’. Return expression after adding a pair of parentheses such that expression evaluates to the smallest possible value. If … Read more

[CODING} Largest Number After Digit Swaps by Parity solution leetcode

You are given a positive integer num. You may swap any two digits of num that have the same parity (i.e. both odd digits or both even digits). Return the largest possible value of num after any number of swaps. largest Number After Digit Swaps by Parity solution leetcode Input: num = 1234 Output: 3412 Explanation: Swap the digit 3 with the digit 1, this results in … Read more

Weightlifting solution codejam 2022 Round 1A

Weightlifting solution codejam   Problem You are following a prescribed training for weightlifting. The training consists of a series of exercises that you must do in order. Each exercise requires a specific set of weights to be placed on a machine. There are WW types of different weights. For example, an exercise may require 33 weights of type A … Read more

GCD vs LCM solution codeforces

GCD vs LCM solution codeforces You are given a positive integer nn. You have to find 44 positive integers a,b,c,da,b,c,d such that a+b+c+d=na+b+c+d=n, and gcd(a,b)=lcm(c,d)gcd(a,b)=lcm⁡(c,d). If there are several possible answers you can output any of them. It is possible to show that the answer always exists. In this problem gcd(a,b)gcd(a,b) denotes the greatest common divisor of aa and bb, and lcm(c,d)lcm⁡(c,d) denotes the least common multiple of cc and dd. Input The input consists … Read more

MinimizOR solution codeforces

MinimizOR solution codeforces   You are given an array aa of nn non-negative integers, numbered from 11 to nn. Let’s define the cost of the array aa as mini≠jai|ajmini≠jai|aj, where || denotes the bitwise OR operation. There are qq queries. For each query you are given two integers ll and rr (l<rl<r). For each query you should find the cost of the subarray al,al+1,…,aral,al+1,…,ar. Input Each test case consists of several test cases. The first line contains … Read more

Array Cloning Technique solution codeforces

Array Cloning Technique solution codeforces   You are given an array aa of nn integers. Initially there is only one copy of the given array. You can do operations of two types: Choose any array and clone it. After that there is one more copy of the chosen array. Swap two elements from any two copies (maybe in the same copy) … Read more