• Kirk Steffke

Challenge 6: Quick Mode

Hey there dev's and dev's-to-be! We have a 'Quick' Lab Coat Challenge for you. Review the challenge, take a look at the starter code, and then give it your best shot. Get the right answer and earn your Lab Coat Badge.


Today’s challenge has to do with finding the mode of a given set of integers


Using the smallest amount of code (least statements - no run on lines of multiple statements!), determine what the “mode” (most frequent number) of a set of integers is. For more information on mode go to: http://www.mathgoodies.com/lessons/vol8/mode.html. For this challenge, if the solution is multimodal (having more than one mode), choose the lowest number of the results (IE: If 2, 3, and 10 are modes for a set of integers, the solution will be 2).

Starter Code

You must use the following code and can only add to the code provided below.

/* LAB COAT CHALLENGE: What is the minimum amount of lines

needed in order to find the mode of the following list

of integers? */

// lists of integers to be used in the asserts

list<Integer> numbers1 = new list<Integer> {2,5,1,2,7,1,2,6,4,6,2,3,8,9};

list<Integer> numbers2 = new list<Integer> {2,5,1,6,7,8,1,5};

list<Integer> numbers3 = new list<Integer> {5,4,7,1,7,2,3,5,4};

list<Integer> numbers4 = new list<Integer> {5,4,7,2,1,7,1,2,5,4};

// Test your code

system.assertEquals(mode(numbers1), new set<Integer> {2});

system.assertEquals(mode(numbers2), new set<Integer> {1,5});

system.assertEquals(mode(numbers3), new set<Integer> {4,5,7});

system.assertEquals(mode(numbers4), new set<Integer>());


// Implement the following method

set<Integer> mode(list<Integer> listOfIntegersToTest) {

set<Integer> returnValues = new set<Integer>();

// Your code here

return returnValues;


Submit Your Answers Here

Recent Posts

At CRM Science, we use our Salesforce expertise to transform your enterprise. Partnering with our clients throughout the Salesforce journey, we work with leaders to strategize and optimize business processes, and design and develop solutions across every Salesforce cloud. We help you maximize the value of the Salesforce platform. 

CRM Science is a Salesforce Gold Consulting Partner and a Salesforce.org Impact Partner. Our strategic consulting services were recognized by Salesforce in four consecutive Salesforce Partner Innovation Awards, an annual recognition for partners that deliver outstanding client success. 

Connect with us
Email Us
860 First Ave, Suite 2
King of Prussia, PA 19406
(484) 775-0333
  • Twitter
  • Facebook
  • YouTube

Copyright © 2011-2021 CRM Science, Inc. All rights reserved.