CJCoding With Joseph
15free / daySign inCreate account
TitleOpen
185
Sum a Vector (STL)Write a function int sumVector(const vector<int>& nums) that returns the sum of all elements using a range-based for loop.
easyNot startedSolve
454
Insert Into a SetA set<int> named s has already been declared for you.
easyNot startedSolve
455
Print a Set in Sorted OrderA set<int> named s already holds the values 5, 1 and 3.
easyNot startedSolve
456
Duplicates Are IgnoredA set<int> named s has been declared for you.
easyNot startedSolve
457
Check Membership with countWrite a function bool contains(const set<int>& s, int x) that returns true if x is stored in the set s and false otherwise.
easyNot startedSolve
458
Erase a Value from a SetA set<int> named s holds 1, 2, 3 and 4, and a loop that prints the set is already written below it.
easyNot startedSolve
459
Set of Strings Sorts AlphabeticallyA set<string> named names has been declared, and a loop that prints each name on its own line is already written.
easyNot startedSolve
460
Count Unique ValuesWrite a function int countUnique(const vector<int>& v) that returns how many distinct values appear in v.
easyNot startedSolve
461
Smallest and Largest in a SetA set<int> named s holds 7, 2, 9 and 4.
easyNot startedSolve
462
multiset Keeps DuplicatesA multiset<int> named ms has been declared for you.
easyNot startedSolve
463
unordered_set LookupWrite a function bool hasWord(const unordered_set<string>& words, const string& x) that returns true if x is one of the words in the set and false otherwise.
easyNot startedSolve
478
Push and Look at the FrontA queue<int> named q has already been created for you.
easyNot startedSolve
479
Pop the FrontA queue<int> named q already holds 10, 20, 30 (10 is at the front).
easyNot startedSolve
480
Drain a QueueA queue<int> named q already holds 1, 2, 3 (1 is at the front).
easyNot startedSolve
481
Queue StatusWrite a function string status(const queue<int>& q) that returns the string "empty" if the queue has no elements, and "not empty" otherwise.
easyNot startedSolve
482
Back of the QueueA queue<int> named q already holds 10, 20, 30 (10 is at the front, 30 is at the back).
easyNot startedSolve
483
Priority Queue Puts Largest on TopA priority_queue<int> named pq has already been created.
easyNot startedSolve
484
Min-Heap with greaterA min-heap has already been declared for you: priority_queue<int, vector<int>, greater<int>> pq;.
easyNot startedSolve
485
Serve the Front CustomerWrite a function void serve(queue<string>& line) that serves the customer at the front of line: print Serving: followed by the front name on its own line, then remove that customer with line.pop().
easyNot startedSolve
486
Deque Push Both EndsA deque<int> named d has already been created, and a loop that prints every element separated by spaces is already written below the comment.
easyNot startedSolve
487
Build a Queue from a VectorWrite a function queue<int> toQueue(const vector<int>& v) that returns a new queue<int> containing the elements of v in the same order, so v[0] ends up at the front of the queue.
easyNot startedSolve
502
Push and PeekA stack<int> named s has already been created in main.
easyNot startedSolve
503
Pop Then PeekA stack<int> named s already holds 1, 2, 3 (3 is on top).
easyNot startedSolve
504
Drain a StackA stack<int> named s already holds 1, 2, 3 (3 is on top).
easyNot startedSolve
505
Top or NoneWrite a function string topOrNone(const stack<int>& s).
easyNot startedSolve
506
Reverse a Word with a StackThe variable word holds "hello", and an empty stack<char> named s and an empty string named result are already declared.
easyNot startedSolve
507
Undo History StackA stack<string> named history already holds three actions pushed in this order: "type a", "type b", "delete" (so "delete" is on top).
easyNot startedSolve
508
Push All from a VectorWrite a function void pushAll(stack<int>& s, const vector<int>& v) that pushes every element of v onto s, in order from v[0] to the last element (so the last element of v ends up on top).
easyNot startedSolve
509
Sum the Top TwoWrite a function int sumTopTwo(stack<int> s) that returns the sum of the two elements nearest the top of the stack.
easyNot startedSolve
510
Size After Mixed OperationsAn empty stack<int> named s is already declared.
easyNot startedSolve
511
Balanced Round BracketsWrite a function bool balanced(const string& s) that returns true when every ( in s is closed by a matching ) in the correct order, and false otherwise.
easyNot startedSolve
526
Fill a std::array in a LoopAn array<int, 5> named a has already been declared for you, and two loops are written: the first loop should fill the array, the second one prints it.
easyNot startedSolve
527
Size of a std::arrayAn array<int, 4> named a has been created with the values {10, 20, 30, 40}.
easyNot startedSolve
528
Sum a std::arrayWrite a function int sumArray(const array<int, 5>& a) that returns the sum of all five elements.
easyNot startedSolve
529
fill With One ValueAn array a of four ints has been declared but not initialized, and a printing loop is already written below it.
easyNot startedSolve
530
front and backAn array<int, 3> named a has been created with the values {3, 5, 9}.
easyNot startedSolve
531
Bounds-Checked at()An array<int, 4> named a holds {1, 2, 3, 4} and an int index is set to 10.
easyNot startedSolve
532
Largest in a std::arrayWrite a function int maxOf(const array<int, 6>& a) that returns the largest of the six values.
easyNot startedSolve
533
Array of Strings With IndexAn array<string, 3> named days has been created with the values {"Mon", "Tue", "Wed"} and a loop over i from 0 to 2 is already written.
easyNot startedSolve
534
Copying a std::arrayThe code already creates array<int, 3> a = {1, 2, 3};, copies it with array<int, 3> b = a;, and then changes b[0] to 99.
easyNot startedSolve
535
Sort a std::arrayAn array<int, 4> named a holds {5, 1, 8, 2}, and a printing loop is already written.
easyNot startedSolve
550
Print with an Iterator LoopA vector v has already been created with the values {1, 2, 3}.
easyNot startedSolve
551
Dereference and AdvanceA vector v has already been created with the values {10, 20, 30}.
easyNot startedSolve
552
Reverse IterationA vector v has already been created with the values {1, 2, 3}.
easyNot startedSolve
553
Modify Through an IteratorA vector v has already been created with the values {1, 2, 3}, and an iterator loop over it is already written.
easyNot startedSolve
554
const_iterator SumWrite a function int sumConst(const vector<int>& v) that adds up every element by looping with a const_iterator from v.cbegin() to v.cend() and returns the total.
easyNot startedSolve
555
Distance Between IteratorsA vector v has already been created with the values {5, 6, 7, 8}.
easyNot startedSolve
556
find Returns an IteratorA vector v has already been created with the values {10, 20, 30, 40} and an int target set to 30.
easyNot startedSolve
557
next and prevA vector v has already been created with the values {1, 2, 3, 4, 5}.
easyNot startedSolve
558
Erase via IteratorA vector v has already been created with the values {1, 2, 3, 4}.
easyNot startedSolve
559
Iterating a std::setA set s has already been created from the values {6, 2, 4}.
easyNot startedSolve
186
Sort a Vector with std::sortUse std::sort to sort a vector of ints in ascending order.
mediumNot startedSolve
187
Count Occurrences with std::mapWrite a function int countOccurrences(const vector<int>& nums, int target) that builds a map<int,int> of value to count, then returns the count stored for target (0 if it never appears).
mediumNot startedSolve
464
Unique Numbers from InputWrite a program that reads an integer N from standard input followed by N integers (all separated by whitespace).
mediumNot startedSolve
465
Count Newly Inserted ValuesWrite a function int insertAll(set<int>& s, const vector<int>& v) that inserts every element of v into s and returns how many of those insertions actually added a new element.
mediumNot startedSolve
466
Common Elements of Two SetsWrite a function vector<int> commonElements(const set<int>& a, const set<int>& b) that returns every value present in both sets, in ascending order.
mediumNot startedSolve
467
Elements Only in the First SetWrite a function set<int> difference(const set<int>& a, const set<int>& b) that returns a new set containing every value that is in a but not in b.
mediumNot startedSolve
468
Remove Duplicate WordsWrite a program that reads words from standard input until the input ends (use while (cin >> word); the words may be spread over several lines).
mediumNot startedSolve
469
Erase Evens While IteratingWrite a function void removeEvens(set<int>& s) that erases every even value from s and leaves the odd values in place.
mediumNot startedSolve
470
First Repeated NumberKeep a set<int> of the values seen so far.
mediumNot startedSolve
471
First Value At Least XWrite a function int firstAtLeast(const set<int>& s, int x) that returns the smallest value in s that is greater than or equal to x.
mediumNot startedSolve
472
Tally a multisetA multiset<int> named ms already holds the values 2, 5, 2, 8, 5, 2.
mediumNot startedSolve
473
Are All Elements Unique?Write a function bool allUnique(const vector<int>& v) that returns true if no value appears more than once in v and false if any value repeats.
mediumNot startedSolve
488
Read Numbers Into a QueueWrite a program that reads an integer N from standard input, followed by N integers (N is at least 1).
mediumNot startedSolve
489
Sum a Queue Without Emptying ItWrite a function int sumQueue(queue<int> q) that returns the sum of every element in the queue.
mediumNot startedSolve
490
Ticket Line SimulationSimulate a ticket line with a queue<string>.
mediumNot startedSolve
491
Top K LargestWrite a function vector<int> topK(const vector<int>& v, int k) that returns the k largest values of v in descending order (largest first), using a priority_queue<int>.
mediumNot startedSolve
492
Reverse a Queue Using a StackWrite a function void reverseQueue(queue<int>& q) that reverses the order of the elements in q in place, using a stack<int> as a helper.
mediumNot startedSolve
493
Print Heap Values DescendingA priority_queue<int> named pq has already been created and filled with 4, 9, 1, 7.
mediumNot startedSolve
494
Priority Queue of PairsA priority_queue<pair<int, string>> tasks; has already been declared.
mediumNot startedSolve
495
Interleave Two QueuesWrite a function queue<int> interleave(queue<int> a, queue<int> b) that returns a new queue built by alternating elements: first the front of a, then the front of b, then the next element of a, then the next of b, and so on.
mediumNot startedSolve
496
Keep Only the Last NWrite a function deque<int> keepLast(const vector<int>& v, int n) that returns a deque holding only the last n elements of v, in their original order.
mediumNot startedSolve
497
Kth Smallest with a Min-HeapWrite a function int kthSmallest(const vector<int>& v, int k) that returns the k-th smallest value of v, where k = 1 means the smallest of all.
mediumNot startedSolve
512
Reverse Numbers from InputWrite a program that reads integers from standard input until the input ends, pushes each one onto a stack<int>, and then pops them all to print the numbers in reverse order on one line, separated by single spaces, followed by a newline.
mediumNot startedSolve
513
Balanced Brackets Three KindsWrite a function bool isBalanced(const string& s) that uses a stack<char> to check whether the brackets in s are balanced.
mediumNot startedSolve
514
Evaluate PostfixWrite a function int evalPostfix(const vector<string>& tokens) that uses a stack<int> to evaluate an expression written in postfix (Reverse Polish) notation.
mediumNot startedSolve
515
Decimal to Binary with a StackWrite a function string toBinary(int n) that returns the binary representation of n as a string, using a stack<int>.
mediumNot startedSolve
516
Sum a Stack CopyWrite a function int sumStack(stack<int> s) that returns the sum of every element in the stack.
mediumNot startedSolve
517
Undo Text EditorWrite a program that simulates a tiny text editor with undo.
mediumNot startedSolve
518
Next Greater ElementWrite a function vector<int> nextGreater(const vector<int>& v) that returns a vector of the same length where position i holds the first element to the right of v[i] that is strictly greater than v[i], or -1 if no such element exists.
mediumNot startedSolve
519
Stack to Vector Bottom FirstWrite a function vector<int> bottomFirst(stack<int> s) that returns the stack's contents as a vector ordered from the bottom of the stack to the top.
mediumNot startedSolve
520
Remove Adjacent DuplicatesWrite a function string removeAdjacent(const string& s) that uses a stack<char> to repeatedly delete pairs of equal adjacent characters until no such pair remains, and returns whatever is left.
mediumNot startedSolve
521
Palindrome Check with a StackWrite a function bool isPalindrome(const string& s) that uses a stack<char> to decide whether s reads the same forwards and backwards.
mediumNot startedSolve
536
Five Numbers from InputWrite a program that reads exactly five integers from standard input (separated by spaces or newlines) into an array<int, 5>, then prints their sum and their average.
mediumNot startedSolve
537
Reverse a std::array In PlaceWrite a function void reverseArray(array<int, 5>& a) that reverses the order of the five elements inside the array itself (no return value, no second array).
mediumNot startedSolve
538
Count Even ValuesWrite a function int countEven(const array<int, 8>& a) that returns how many of the eight elements are even.
mediumNot startedSolve
539
Sum Any Size (Template Parameter)Write a function template template <size_t N> int sumAny(const array<int, N>& a) that returns the sum of all elements of an array<int, N> for any N.
mediumNot startedSolve
540
3x3 Grid with Nested std::arrayA variable grid of type array<array<int, 3>, 3> has been declared for you.
mediumNot startedSolve
541
Index of a ValueWrite a function int indexOf(const array<int, 6>& a, int x) that returns the index (0 to 5) of the first element equal to x, or -1 if x does not appear in the array.
mediumNot startedSolve
542
Rotate Left by OneWrite a function void rotateLeft(array<int, 5>& a) that moves every element one position to the left, and moves the element that was at index 0 to the end.
mediumNot startedSolve
543
Swap Two ArraysThe code already creates array<int, 3> a = {1, 2, 3}; and array<int, 3> b = {4, 5, 6};.
mediumNot startedSolve
544
Weekly Temperature ReportAn array<double, 7> named temps holds one temperature per day of the week: {24.5, 26.0, 31.5, 22.0, 28.0, 25.5, 27.3}.
mediumNot startedSolve
545
Compare Two ArraysWrite a function bool sameContents(const array<int, 4>& a, const array<int, 4>& b) that returns true when the two arrays hold the same values in the same order and false otherwise.
mediumNot startedSolve
560
Sum Between Two IteratorsWrite a function int sumRange(vector<int>::iterator first, vector<int>::iterator last) that returns the sum of every element in the half-open range from first to last.
mediumNot startedSolve
561
Erase Every Matching ValueWrite a function void removeValue(vector<int>& v, int x) that removes every element equal to x from v, keeping the other elements in their original order.
mediumNot startedSolve
562
Insert Before a ValueWrite a function void insertBefore(vector<int>& v, int target, int val) that: 1.
mediumNot startedSolve
563
Second Largest with Iterator ArithmeticWrite a function int secondLargest(vector<int> v) that returns the second-largest value in v.
mediumNot startedSolve
564
Print Every Other ElementWrite a function void printEveryOther(const vector<int>& v) that prints the elements at positions 0, 2, 4, ...
mediumNot startedSolve
565
Reverse a String with Reverse IteratorsWrite a function string reversed(const string& s) that returns a new string containing the characters of s in reverse order, built from s.rbegin() and s.rend().
mediumNot startedSolve
566
Index of the MaximumWrite a function int indexOfMax(const vector<int>& v) that returns the 0-based index of the largest element in v using max_element (from <algorithm>).
mediumNot startedSolve
567
Iterate a Map with IteratorsA map<string, int> named stock has already been created with apple mapped to 3 and pear mapped to 5.
mediumNot startedSolve
568
Reverse Input with Reverse IteratorsWrite a program that reads whole numbers from standard input until there is no more input (end of file), stores them in a vector<int>, and then prints them in reverse order on one line, each number followed by a single space, ending with a newline.
mediumNot startedSolve
569
First Half by Iterator RangeWrite a function vector<int> firstHalf(const vector<int>& v) that returns a new vector containing the first v.size() / 2 elements of v (integer division, so for an odd size the middle element is left out).
mediumNot startedSolve
474
Unique Word TrackerBuild a class UniqueWords that stores the distinct words in a set<string>.
hardNot startedSolve
475
Number Set Range QueriesBuild a class NumberSet that stores distinct integers in a set<int> and answers range queries.
hardNot startedSolve
476
Set Algebra From InputRead two lines from standard input.
hardNot startedSolve
477
Inventory with multisetBuild a class Inventory that stores item names in a multiset<string>, so the same name can be held several times.
hardNot startedSolve
498
Printer Job SchedulerBuild a class PrintQueue that serves print jobs first-come, first-served, storing each job's name and page count in a queue.
hardNot startedSolve
499
Emergency Room TriageBuild a class Triage that decides which emergency-room patient is seen next, using a priority_queue with a custom comparator.
hardNot startedSolve
500
Round-Robin SchedulerWrite a round-robin CPU scheduler.
hardNot startedSolve
501
Josephus Elimination Ordern people numbered 1 to n stand in a circle.
hardNot startedSolve
522
Min StackBuild a class MinStack that behaves like a normal stack of ints but can also report its smallest element in constant time — getMin() must not scan the stack.
hardNot startedSolve
523
Infix to PostfixWrite a function string toPostfix(const string& expr) that converts an infix arithmetic expression to postfix notation using a stack of operators.
hardNot startedSolve
524
Browser HistoryBuild a class BrowserHistory that models the back and forward buttons of a web browser using two stacks.
hardNot startedSolve
525
Queue Made of Two StacksBuild a class StackQueue that behaves like a first-in first-out queue of ints but is implemented with two stack<int> members only (no queue, deque or vector).
hardNot startedSolve
546
Fixed-Size Ring BufferBuild a class RingBuffer that stores its values in an array<int, 4> (capacity 4) and never allocates anything else.
hardNot startedSolve
547
Tic-Tac-Toe WinnerA tic-tac-toe board is an array<array<char, 3>, 3>: b[row][col] is 'X', 'O', or '.' for an empty cell.
hardNot startedSolve
548
2x2 Matrix MultiplyA 2x2 matrix is an array<array<int, 2>, 2>, where m[r][c] is the value in row r, column c.
hardNot startedSolve
549
Digit Histogram from InputWrite a program that reads non-negative integers from standard input until the input ends.
hardNot startedSolve
570
Countdown Range ClassCreate a class Countdown with: 1.
hardNot startedSolve
571
Remove Duplicates Keeping OrderWrite a function void dedupe(vector<int>& v) that modifies v in place so that each value appears only once, keeping the FIRST occurrence of every value and preserving the original relative order.
hardNot startedSolve
572
Merge Two Sorted VectorsWrite a function vector<int> mergeSorted(const vector<int>& a, const vector<int>& b) where a and b are each sorted ascending.
hardNot startedSolve
573
Linked List with IteratorCreate a class IntList, a singly linked list of ints, with: 1.
hardNot startedSolve