ContentsFoundations to FrontierBezhig

cp/cp01/gate/gate.h

All lab code. Download this file.

#pragma once
// CP01 mastery gate. Closed book, no AI, 40 minutes for all three, starting from this file.
// Run from the cp01 folder with   .\run.ps1 -Gate
// Each body starts as a `throw`; delete it when you write the function.

#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>

// G1. Return how many different values v holds. An empty v holds 0 different values.
inline int countDistinct(const std::vector<int>& v) {
    throw std::logic_error("G1, countDistinct: not written yet");
}

// G2. s is not empty and holds only the lowercase letters 'a' to 'z'. Return the letter
// that appears most often; if several tie, return the one that comes first in the alphabet.
inline char mostCommonLetter(const std::string& s) {
    throw std::logic_error("G2, mostCommonLetter: not written yet");
}

// G3. Return true if two values at different positions in v add up to target.
// Every value, and target, lies between -1'000'000'000 and 1'000'000'000.
// It must stay fast for 300'000 values.
inline bool hasPairWithSum(const std::vector<int>& v, int target) {
    throw std::logic_error("G3, hasPairWithSum: not written yet");
}