Sales by Match

Problem Description: There is a large pile of socks that must be paired by color. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. Example n = 7 ar = [1, 2, 1, 2, 1, 3, 2] There is one pair of color 1 and one of...

READ MORE Sales by Match

Counting Valleys

Problem Description: An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly steps steps, for every step it was noted if it was an uphill, U, or a downhill, D step. Hikes always start and end at sea level, and each step up or down represents a 1 unit change in altitude. We define...

READ MORE Counting Valleys

Sorting: Comparator

Problem Description: Comparators are used to compare two objects. In this challenge, you’ll create a comparator and use it to sort an array. The Player class is provided in the editor below. It has two fields: name: a string. score: an integer. Given an array of Player objects, write a comparator that sorts them in order of decreasing score. If...

READ MORE Sorting: Comparator