Find Niceness ๐บ
Learn this problemProblem statement
In a tranquil village school, there are two students named Ramu and Sonu, each possessing a collection of N distinct chalks. Each student's chalks are of different lengths, represented by N positive integers. Ramu has arranged his collection of N chalks in a specific order based on their lengths. Sonu is eager to organize his own N chalks in a way that mimics Ramu's arrangement in terms of length changes i.e. if in Ramu's arrangement the kth chalk is bigger than the k+1th chalk, in Sonu's arrangement also the kth chalk will be bigger than the k+1th arrangement, alternately if it is smaller in Ramu's arrangement, then it will be smaller in Sonu's as well.
Sonu was busy arranging his chalks, when his teacher told him to also maximize the "niceness" of his arrangement. Here, the "niceness" of the arrangement is defined as the sum of the absolute length differences between all adjacent chalks in the arrangement.
Write a program to assist Sonu in achieving both the objectives: first, to mimic Ramu's length variation order, and second, to maximize the overall niceness of the arrangement.
Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings anywhere in the program, as these contribute to the standard output, and test cases will fail.
Objective
Find the maximum achievable niceness resulting from the arrangement of Sonu's chalk collection to mimic Ramu's chalk arrangement.
Function
findNiceness(N: int, a: int[], b: int[]) โ intExamples
Example 1
N = 4a = [7, 1, 4, 9]b = [1, 2, 3, 4]return = 7Constraints
Unknown for now ๐ฃMore Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW ยท Seen Jul 2026
- Root of the Largest TreePHONE SCREEN ยท Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW ยท Seen Jul 2026
- Alternating Parity PermutationsOA ยท Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW ยท Seen Jun 2026
- Word LadderPHONE SCREEN ยท Seen Jun 2026