You are given two independent tasks.
Task A (Maximize calories over jumps):
-
There are n blocks with integer heights height[i] ≥ 0.
-
You start on the ground at height 0. You must visit every block exactly once in any order. After the first jump from the ground to some block, you may only jump between blocks; you cannot return to the ground.
-
The calories consumed for a jump from a location of height x to a location of height y is (x − y)^2 (the ground’s height is
0).
-
Choose an order of visiting the n blocks that maximizes the total calories across all n jumps (ground → first block plus the n−1 subsequent block-to-block jumps). Return the maximum total as an integer.
-
Example: n = 3, height = [5, 2, 5] ⇒ 43.
-
Describe your algorithm and analyze its time and space complexity.
Task B (Password similarity under character-removal):
-
For each test case, you are given two lowercase strings password1 and password2.
-
You may remove all occurrences of at most one chosen character from password1, and independently remove all occurrences of at most one chosen character from password2. You may also choose to remove nothing from either string.
-
After these removals, the strings are considered similar if they are anagrams (i.e., they have identical character multisets).
-
For each test case, return true if the strings can be made similar under this rule, otherwise return false.
-
Example: password1 = "safddadfs", password2 = "famafmss" ⇒ true (remove all 'd' from password1 and all 'm' from password
2).
-
Describe your algorithm and analyze its time and space complexity.