Forming a Magic Square
We define a magic square to be an n * n matrix of distinct positive integers from 1 to n^2 where the sum of any row, column, or diagonal of length n is always equal to the same number: the magic constant. You will be given a 3 * 3 matrix s of integers in the inclusive range [1, 9]. We can convert any digit a to any other digit b in the range [1, 9] at cost of | a - b |. Given s, convert it into a magic square at minimal cost. Print this cost on a new line. Note: The resulting magic square
View Solution →Picking Numbers
Given an array of integers, find the longest subarray where the absolute difference between any two elements is less than or equal to 1. Example a = [1, 1, 2, 2, 4, 4, 5, 5, 5] There are two subarrays meeting the criterion: [1, 1, 2, 2] and [4, 4, 5, 5, 5]. The maximum length subarray has 5 elements. Function Description Complete the pickingNumbers function in the editor below. pickingNumbers has the following parameter(s): int a[n]: an array of integers Returns int: t
View Solution →Climbing the Leaderboard
An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this: The player with the highest score is ranked number 1 on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number. Example ranked = [100, 90, 90, 80] player = [70, 80, 105] The ranked players will have ranks 1, 2, 2, and 3, respectivel
View Solution →The Hurdle Race
A video player plays a game in which the character competes in a hurdle race. Hurdles are of varying heights, and the characters have a maximum height they can jump. There is a magic potion they can take that will increase their maximum jump height by 1 unit for each dose. How many doses of the potion must the character take to be able to jump all of the hurdles. If the character can already clear all of the hurdles, return 0. Example height = [1, 2, 3, 3, 2] k = 1 The character can ju
View Solution →Designer PDF Viewer
When a contiguous block of text is selected in a PDF viewer, the selection is highlighted with a blue rectangle. In this PDF viewer, each word is highlighted independently. For example: There is a list of 26 character heights aligned by index to their letters. For example, 'a' is at index 0 and 'z' is at index 05. There will also be a string. Using the letter heights given, determine the area of the rectangle highlight in mm^2 assuming all letters are 1mm wide. Example h = [1, 3, 1, 3, 1
View Solution →