title-img


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 →

Words Score Python

In this challenge, the task is to debug the existing code to successfully execute all provided test files. Consider that vowels in the alphabet are a, e, i, o, u and y. Function score_words takes a list of lowercase words as an argument and returns a score as follows: The score of a single word is 2 if the word contains an even number of vowels. Otherwise, the score of this word is . The score for the whole list of words is the sum of scores of all words in the list. Debug the given

View Solution →

Default Arguments Python

In this challenge, the task is to debug the existing code to successfully execute all provided test files. Python supports a useful concept of default argument values. For each keyword argument of a function, we can assign a default value which is going to be used as the value of said argument if the function is called without it. For example, consider the following increment function: def increment_by(n, increment=1): return n + increment The functions works like this: >>> increm

View Solution →