Given a non-empty array of type int
, return a new array containing the elements from the original array that came before thefirst 4 in...
CodeWorkouts X101 - X200 More or Less
Score: 0 / 45.0
About 45 more advanced exercises, including recursion and arrays
Exercises
Given an array of int
values, return true if the group of n
numbers at the start of the array is the same as the group of n
numbers at...
Say that a "clump" in an array is a series of 2 or more adjacent elements of the same value. Return the number of clumps in the given...
Given an array, return an array that contains exactly the same numbers as the original array, but rearranged so that every 4 is...
Given a string, does "xyz" appear in the middle of the string? To define middle, we'll say that the number of chars to the left and right...
Given a string str
and an int n
, return a string made of the first n
characters of the string, followed by the first n - 1
characters of...
Return an array that contains the exact same numbers as the given array, but rearranged so that all the even numbers come before all the...
Given n
>= 0, create an array with the pattern {1, 1, 2, 1, 2, 3, ... 1, 2, 3 .. n
} (spaces added to show the grouping). Note that...
Given a string of any length, return a new string where the last 2 chars, if present, are swapped, so "coding" yields "codign".
Given a string, return true
if "bad" appears starting at index 0 or 1 in the string, such as with "badxxx" or "xbadxx" but not "xxbadxx"....
Return a version of the given string, where for every star (*) in the string the star and the character immediately to its left and the...
Return true
if somewhere in the array, there are three increasing adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25.
Given start
and end
integers, return a new array containing the sequence of integers from start
up to but not including end
, so start
= 5...
Return an array that is "left shifted" by one--so for an input of {6, 2, 5, 3}, the method returns {2, 5, 3, 6}. You may modify and...
Given a non-empty array of int
s, return a new array containing the elements from the original array that come after the last 4 in the...
We'll say that an element in an array is "alone" if there are values before and after it, and those values are different from it. Return...
Return an array that contains the exact same numbers as the given array, but rearranged so that all the zeros are grouped at the start of...
Given two arrays of int
s sorted in increasing order, called outer
and inner
, return true
if all of the numbers in inner
also appear in ...
Given n
>= 0, create an array of length n * n
with the following pattern, shown here for n
= 3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces...
Given an out
string of length 4, such as "<<>>", and a word
, return a new string where the word
is in the middle of the out
...
Given a string, return a new string made of 3 copies of the last 2 chars of the original string. The string's length will be at least 2.
...Given a string, return the string made of its first two chars, so the string "Hello" yields "He". If the string is shorter than length 2,...
Return true
if the string "cat" and "dog" appear the same number of times in the given string.
Return true if the given string contains a "bob" string, but where the middle 'o' character can be any character.
Given two strings, word
and a separator sep
, return a big string made of count
occurrences of the word
, separated by the separator...
Given a string, count the number of words ending in 'y' or 'z'--so the 'y' in "heavy" and the 'z' in "fez" count, but not the 'y' in...
We have bunnies standing in a line, numbered 1, 2, ... The odd bunnies (1, 3, 5, ...) have the normal 2 ears. The even bunnies (2, 4,...
Given a non-negative int n
, compute recursively (no loops) the count of the occurrences of 8 as a digit, except that an 8 with another 8...
Given an array of int
s, compute recursively the number of times that the value 11 appears in the array (no loops). We'll use the...
Given a string, compute recursively a new string where all the adjacent chars are now separated by a "*". So given "hello", return...
Given a string that contains a single pair of parenthesis, compute recursively a new string containing only the parentheses and their...
Given a string and a non-empty substring sub
, compute recursively if at least n
copies of sub
appear in the string somewhere, possibly...
Given a string str
and a non-empty substring sub
, compute recursively the largest substring which both starts and ends with sub
and...
Given a string, return true
if it is a nesting of zero or more pairs of parentheses, like "(())" or "((()))". Suggestion: check the first...
Given a string, compute the number of times lowercase "hi" appears in the string. Make the countHi
be recursive.
Count recursively (no loops) the total number of "abc" and "aba" substrings that appear in the given string.
Given a string, compute recursively (no loops) a new string where all the lowercase 'x' chars have been changed to 'y' chars.
Given base
and n
that are both 1 or more, compute recursively (no loops) the value of base
to the n
power, so powerN(3, 2)
is 9 (3...
We'll say that a "pair" in a string is two instances of the same character separated by another character. So in "AxA", the A's make a...
Given a string, return a recursively "cleaned" string where adjacent chars that are the same have been reduced to a single char. So...
Given an array of int
s, compute recursively if the array contains somewhere a value followed immediately by that same value times 10....
Given a string, compute recursively a new string where all the 'x' chars have been removed.
Given an array of int
s, compute recursively if the array contains a 6. We'll use the convention of considering only the part of the array...
Given a non-negative int n
, return the count of the occurrences of 7 as a digit, so for example 717 yields 2. (no loops). Note that mod (...
Given a string, compute recursively (no loops) a new string where all appearances of "pi" have been replaced by "3.14".