← Back to Course Overview

Sprint Challenge

Overview

This sprint challenge will test your understanding of the concepts covered in this sprint, including:

Challenge Requirements

You will be required to:

Project Setup

Follow these steps to get started:

  1. Access the sprint challenge through LeetCode
  2. Review the requirements carefully
  3. Plan your approach before coding
  4. Test your solutions thoroughly

Submission Guidelines

To submit your work:

Grading Rubric

Your submission will be evaluated based on:

Sprint Challenge Study Guide and Practice Problems

To prepare for the sprint challenge, make sure you understand the following concepts and can solve similar problems:

Key Concepts Review

Practice Problems

Practice Problem 1: Reverse Words

Write a function that reverses the words in a string without using the built-in reverse() method.

Example:

Input: "Hello World"
Output: "World Hello"

Solution:

function reverseWords(str) {
  // Split the string into an array of words
  const words = str.split(' ');
  
  // Create a new array to store words in reverse order
  const reversedWords = [];
  
  // Iterate through words array in reverse
  for (let i = words.length - 1; i >= 0; i--) {
    reversedWords.push(words[i]);
  }
  
  // Join the reversed words with spaces
  return reversedWords.join(' ');
  
  // One-liner alternative:
  // return str.split(' ').reverse().join(' ');
}

console.log(reverseWords("Hello World")); // "World Hello"
console.log(reverseWords("JavaScript is fun")); // "fun is JavaScript"

Practice Problem 2: Find Missing Number

Given an array containing n distinct numbers taken from 0 to n, find the missing number.

Example:

Input: [3,0,1]
Output: 2

Input: [9,6,4,2,3,5,7,0,1]
Output: 8

Solution:

function findMissingNumber(nums) {
  // Calculate expected sum of numbers from 0 to n
  const n = nums.length;
  const expectedSum = (n * (n + 1)) / 2;
  
  // Calculate actual sum of numbers in the array
  const actualSum = nums.reduce((sum, num) => sum + num, 0);
  
  // The difference is the missing number
  return expectedSum - actualSum;
}

console.log(findMissingNumber([3,0,1])); // 2
console.log(findMissingNumber([9,6,4,2,3,5,7,0,1])); // 8

Practice Problem 3: Count Characters

Write a function that counts the occurrences of each character in a string and returns an object with the results.

Example:

Input: "hello world"
Output: { h: 1, e: 1, l: 3, o: 2, ' ': 1, w: 1, r: 1, d: 1 }

Solution:

function countCharacters(str) {
  // Create an empty object to store character counts
  const charCount = {};
  
  // Iterate through each character in the string
  for (let char of str) {
    // If character is already in the object, increment count
    if (charCount[char]) {
      charCount[char]++;
    } 
    // Otherwise, add character to object with count of 1
    else {
      charCount[char] = 1;
    }
    
    // Alternative using the || operator:
    // charCount[char] = (charCount[char] || 0) + 1;
  }
  
  return charCount;
}

console.log(countCharacters("hello world")); 
// { h: 1, e: 1, l: 3, o: 2, ' ': 1, w: 1, r: 1, d: 1 }

Tips for Success

  1. Read the problems carefully - Make sure you understand what each problem is asking before starting to code.
  2. Plan before you code - Take a few minutes to think about your approach and pseudocode the solution.
  3. Start with simple solutions - Get a working solution first, then optimize if needed.
  4. Test edge cases - Check your solution with empty arrays, strings, negative numbers, etc.
  5. Use descriptive variable names - This helps both you and the evaluator understand your code better.
  6. Comment your code - Explain your thought process, especially for complex parts.
  7. Time management - If you're stuck on a problem for too long, move on and come back to it later.
  8. Review your code - Before submitting, check for bugs, typos, and unnecessary code.

Common Mistakes to Avoid

Career Readiness Quiz

Complete the career readiness quiz to demonstrate your understanding of professional development concepts.

Additional Resources