You are given a positive integer n. You can perform the following operation any number of times: Add or subtract a power of 2 from n. Your goal is to find the minimum number of operations required to make n equal to 0.
You are given a positive integer array nums. A subset of the array nums is square-free if the product of its elements is a square-free integer. A square-free integer is an integer that is not divisible by any perfect square other than 1. Return the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 10^9 + 7.
You are given an array of positive integers nums and a positive integer k. A subset of nums is considered beautiful if it does not contain any two integers whose absolute difference is equal to k. Your task is to return the number of non-empty beautiful subsets of the array nums. A subset is formed by deleting some (possibly none) elements from nums, and two subsets are different if their selected indices are different.
You are given a string s, a string chars of distinct characters, and an integer array vals of the same length as chars. The value of each character is determined by either its position in the alphabet or a corresponding value in the vals array if it is present in chars. The cost of a substring is the sum of the values of each character in that substring. Your goal is to find the maximum cost of any substring of s.
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’.
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.