Download results
Showing 0-0 of 0 results
Items per page:
10
25
50
100
#
Exercise Title
Features
Description
Platform
Keywords
1
List of numbers
Code Completion
When printing the elements in an array, you want commas between the elements, such as
CodeCheck
Arrays and Array Lists
2
Short words
Code Completion
You want to collect all “short” words in an array of words, that is, words with at most three characters....
CodeCheck
Arrays and Array Lists
3
Select a short word
Code Completion
You want to pick a particular “short” word in an array of words, that is, words with at most three...
CodeCheck
Arrays and Array Lists
4
Diagonals on board
Code Completion
You are given a class similar to the TicTacToe board in Section 7.6, but the board can have more than...
CodeCheck
Arrays and Array Lists
5
Border on board
Code Completion
You are given a class similar to the TicTacToe board in Section 7.6, but the board can have more than...
CodeCheck
Arrays and Array Lists
6
Run lengths
Code Completion
A run is a sequence of adjacent repeated values. For example, the array with elements
CodeCheck
Arrays and Array Lists
7
Same beginning and end sequence
Code Completion
Your task is to determine whether an array has the same sequence of numbers at the beginning and the end,...
CodeCheck
Arrays and Array Lists
8
Remove short words
Code Completion
Remove all short words (that is, words of length at most 3) from an array. Move down the remaining array...
CodeCheck
Arrays and Array Lists
9
Number of even and odd elements
Code Completion
Count the number of even and odd elements in an array of integers. Since you must return two counts, place...
CodeCheck
Arrays and Array Lists
10
Letter frequency (count)
Code Completion
Write a method that computes how often each letter A-Z or a-z occurs in a string. Don't distinguish between upper-...
CodeCheck
Arrays and Array Lists
11
Letter frequency (percentage)
Code Completion
Write a method that computes the frequency (as a percentage between 0.0 and 1.0) of each letter A-Z or a-z...
CodeCheck
Arrays and Array Lists
12
Swap first and second half of array
Code Completion
Your task is to complete a method that swaps the first and second half of an array of integers. For...
CodeCheck
Arrays and Array Lists
13
Swap adjacent elements in array
Code Completion
Your task is to complete a method that swaps adjacent values in an array of integers. For example, if the...
CodeCheck
Arrays and Array Lists
14
Railfence cypher
Code Completion
A simple way of encoding a message is the railfence cypher. The message is written downwards and diagonally on rails...
CodeCheck
Arrays and Array Lists
15
Employee Pay with Overtime
Code Completion
Employees get paid time and a half for the weekly work hours in excess of 40 hours. For example, an...
CodeCheck
Branches
16
Middle Letter
Code Completion
Complete the getMiddle method that gets the middle character from a word if the word length is odd, or the...
CodeCheck
Branches
17
Check for Valid Answers
Code Completion
Consider a program that administers multiple-choice quizzes. The student needs to provide a response such as A or D. Your...
CodeCheck
Branches
18
Overlapping sets
Code Completion
An open interval is the set of all numbers between a lower and upper bound. In mathematical notation, we write
CodeCheck
Branches
19
Intersecting Lines
Code Completion
A non-vertical line in the plane can be described by the slope/y intercept equation
CodeCheck
Branches
20
Sort Names
Code Completion
We consider names of people that consist of first and last names, such as Joe Smith. When you sort names,...
CodeCheck
Branches
21
Number guessing game
Code Completion
A simple guessing game asks the player to guess a number between 1 and 50. Hints are returned depending on...
CodeCheck
Branches
22
All the same
Code Completion
Write a method to test whether four numbers are all the same. For example,
CodeCheck
Branches
23
All different
Code Completion
Write a method to test whether three numbers are all different. For example,
CodeCheck
Branches
24
All the same sign
Code Completion
Write a method to test whether three numbers have the same sign (positive, zero, or negative). For example,
CodeCheck
Branches
25
BankAccount with Service Charge
Code Completion
Change the withdraw method of the BankAccount class so that a charge of $1.00 is deducted for each withdrawal.
CodeCheck
Classes
26
BankAccount with Transaction Count
Code Completion
Change the deposit and withdraw methods of the BankAccount class so that a count of transactions is updated. For example,...
CodeCheck
Classes
27
BankAccount with Bonus for Opening Account
Code Completion
Implement a BankAccount that pays a bonus of $10 for each new account.
CodeCheck
Classes
28
ClassSchedule
Code Completion
Implement a class ClassSchedule with a title (a string), days the class meets (a string), a start meeting time (a...
CodeCheck
Classes
29
ClassSchedule with setDays and set times
Code Completion
A ClassSchedule class has been designed to represent a class that is scheduled at given days and times. Sometimes class...
CodeCheck
Classes
30
ClassSchedule with getDays and set times
Code Completion
Your task is to write a tester class for the ClassSchedule class given below. You should test the getTime and...
CodeCheck
Classes
31
XML Map Labels
Code Completion
The latitude, longitude and place name are used to label a map. Implement a class with latitude and longitude as...
CodeCheck
Classes
32
XML Map Labels convert to decimal degrees
Code Completion
The latitude, longitude and place name are used to label a map. Implement a class with latitude and longitude as...
CodeCheck
Classes
33
Reimplement Person class to increase cohesion
Code Completion
Consider the Person class below.
CodeCheck
Designing Classes
34
Swap values by using an array
Code Completion
A Java method cannot update primitive type parameters. For example, the following method does not work as intended:
CodeCheck
Designing Classes
35
Preconditions for Sentence constructor
Code Completion
The constructor of the Sentence class below makes assumptions about the text parameter:
CodeCheck
Designing Classes
36
Static method for computing number of binary digits in n
Code Completion
Supply a static method that computes the number of binary digits in a given integer. For example,
CodeCheck
Designing Classes
37
Static field to count number of objects
Code Completion
Add a private static variable to the Coin class that counts the total number of coins that were constructed. Also...
CodeCheck
Designing Classes
38
Reimplement Vehicle class to increase cohesion
Code Completion
Consider the Vehicle class below.
CodeCheck
Designing Classes
39
Introduce class to implement method that mutates value
Code Completion
A Java method cannot update primitive type parameters. For example, the following program cannot work as intended:
CodeCheck
Designing Classes
40
Preconditions for SalaryBonus constructor
Code Completion
The constructor of the SalaryBonus class below makes the following assumptions;
CodeCheck
Designing Classes
41
Static method for counting the number of times a character appears in a string
Code Completion
Supply a static method that counts the number of times that a specific character appears in a given string. For...
CodeCheck
Designing Classes
42
Static field to maintain the total value of Coin objects created
Code Completion
Add a private static variable to the Coin class that maintains the total value of all coins that were constructed....
CodeCheck
Designing Classes
43
Liftoff threads
Code Completion
We want to simulate multiple rocket launches by ACME Rocket Inc. Each launch has a countdown, like this
CodeCheck
Concurrency
44
Synchronizing multiple summation threads
Code Completion
We will divide the work of computing the sum of all values in an array over multiple threads. Each thread...
CodeCheck
Concurrency
45
Using conditions for completion count
Code Completion
We will divide the work of computing the maximum of all values in an array over multiple threads. Each thread...
CodeCheck
Concurrency
46
Launching multiple summation threads and using yield
Code Completion
We will divide the work of computing the sum of all values in an array over multiple threads. Each thread...
CodeCheck
Concurrency
47
A slow sorting algorithm with two threads
Code Completion
Consider the following algorithm to sort an array of strings and remove duplicates, using two threads.
CodeCheck
Concurrency
48
Normalizing Angles
Code Completion
When you work with angle measurements, you often want them normalized or converted into the range between 0 . ....
CodeCheck
Fundamental Data Types
49
Last n Characters
Code Completion
Write a method that gets the last n characters from a string. For example, last("Hello, World!", 5) should return the...
CodeCheck
Fundamental Data Types
50
Length of Line
Code Completion
Complete the following function that computes the length of a line segment with end points (x1, y1) and (x2, y2)....
CodeCheck
Fundamental Data Types
51
Initials
Code Completion
Complete the initials method in the class below. For example, the call initials("Harry", "Joseph", "Hacker") should return the string "HJH".
CodeCheck
Fundamental Data Types
52
Timer
Code Completion
The following timer class measures the total time that has elapsed after timing a number of events. Your job is...
CodeCheck
Fundamental Data Types
53
Decimal Degrees
Code Completion
Latitude and longitude are measured in degrees, minutes and seconds. As with time measurements, there are 60 seconds to a...
CodeCheck
Fundamental Data Types
54
Degree, Minute, Second
Code Completion
Latitude and longitude can be expressed in the form of decimal degrees. Another form, often used on maps, is degrees,...
CodeCheck
Fundamental Data Types
55
Distance between two points on earth
Code Completion
A position on the planet Earth is specified by latitude and longitude (in degrees). The distance between two points on...
CodeCheck
Fundamental Data Types
56
Swap first and last name
Code Completion
Write a method getLastFirst whose parameter is a string containing a name such as "Harry Smith" and that returns a...
CodeCheck
Fundamental Data Types
57
Change Firstname Lastname to Lastname, Firstname
Code Completion
Fred fills out his time sheet at work, but he needs to provide the number of minutes worked. He only...
CodeCheck
Fundamental Data Types
58
Generic matrix class as array of arrays
Code Completion
Your task is to complete the implementation of a generic Matrix class. A matrix is a two-dimensional arrangement of elements....
CodeCheck
Generic Types
59
Generic matrix class as linear array
Code Completion
Your task is to complete the implementation of a generic Matrix class. A matrix is a two-dimensional arrangement of elements....
CodeCheck
Generic Types
60
Generic matrix class as a map with integer keys
Code Completion
Your task is to complete the implementation of a generic Matrix class. A matrix is a two-dimensional arrangement of elements....
CodeCheck
Generic Types
61
Generic matrix class as a map with integer pair keys
Code Completion
Your task is to complete the implementation of a generic Matrix class. A matrix is a two-dimensional arrangement of elements....
CodeCheck
Generic Types
62
Pair class with compareTo method
Code Completion
We sometimes want to compare two Pair objects, for example, when using pairs as keys in a tree map.
CodeCheck
Generic Types
63
Generic pair with min method
Code Completion
CodeCheck
Generic Types
64
Generic method for filling an array
Code Completion
The class below has a static method which sets all elements of an array to a value. The method is...
CodeCheck
Generic Types
65
Generic replicate method
Code Completion
Implement the generic replicate method. It should return a list containing multiple copies of the given value.
CodeCheck
Generic Types
66
Finding the first match for a predicate
Code Completion
Recall that a predicate is a method with a Boolean return value. The Predicate interface can be used to test...
CodeCheck
Generic Types
67
Finding all matches for a predicate
Code Completion
Recall that a predicate is a method with a Boolean return value. The Predicate interface can be used to test...
CodeCheck
Generic Types
68
Extend ASCII art rectangle to filled rectangle
Code Completion
You are given a class Rectangle that produces ASCII art rectangles such as the following:
CodeCheck
Inheritance
69
Extend ASCII art rectangle to tiled rectangle
Code Completion
You are given a class Rectangle that produces ASCII art rectangles such as the following:
CodeCheck
Inheritance
70
Implement LabeledPoint.toString
Code Completion
A labeled point has an x- and y-position and a label.
CodeCheck
Inheritance
71
Implement LabeledPoint.equals
Code Completion
A labeled point has an x- and y-position and a label.
CodeCheck
Inheritance
72
Implement Tile.translate
Code Completion
A Tile class extends Rectangle. It is to be used for non-overlapping tilings. Your task is to override the translate...
CodeCheck
Inheritance
73
Auto extending Vehicle and overriding getID
Code Completion
All vehicles used for transportation in the U.S. must have identification, which varies according to the type of vehicle. For...
CodeCheck
Inheritance
74
Inherit and call a superclass constructor
Code Completion
Complete the Car class below so that it inherits from the given Vehicle class. Cars lose value over time. In...
CodeCheck
Inheritance
75
An enum type describing chemical elements
Code Completion
Enumerated types in Java are quite powerful, in that they can contain methods and instance variables. An enum type class...
CodeCheck
Inheritance
76
Using an Abstract Class
Code Completion
Light bulbs can be identified by type and can be measured by the amount of lumens produced per watt of...
CodeCheck
Inheritance
77
Overriding the equals Method
Code Completion
All vehicles used for transportation in the U.S. must have identification, which varies according to the type of vehicle. For...
CodeCheck
Inheritance
78
Make Sentence implement Measurable
Code Completion
Complete the Sentence class below so that it implements the Measurable interface. The measure of a sentence should be the...
CodeCheck
Interfaces
79
Make a measurer for words
Code Completion
In this exercise, we use the Word class from chapter 6 (with the bugs fixed). You should not change the...
CodeCheck
Interfaces
80
Implement the Doublable interface
Code Completion
Some objects can be doubled, for example a bank account. The result would be a bank account with twice the...
CodeCheck
Interfaces
81
Provide a RectangleDoubler class that implements the Doubler interface
Code Completion
Some objects can be doubled, for example a bank account. The result would be a bank account with twice the...
CodeCheck
Interfaces
82
Implement an Interface to Change Rectangle Dimensions
Code Completion
Complete the RectangleManager class below so that it implements the given Adjuster interface. The implementation should use the h and...
CodeCheck
Interfaces
83
Implement an Interface to Provide Museum's Car Count
Code Completion
Complete the CarMuseum class below so that it implements the given Measurable interface. Your tasks are as follows:
CodeCheck
Interfaces
84
Using Anonymous Objects
Code Completion
Modify the PolygonTester class below so that it uses anonymous objects where possible. Objects that are only used once should...
CodeCheck
Interfaces
85
Creating the Movement Interface
Code Completion
Create the Movement interface below and the abstract methods move and getPosition, which are implemented by the Ship and Auto...
CodeCheck
Interfaces
86
Using instanceof for Converting Between Animal Types
Code Completion
The Cat and Dog class below implement the Animal interface. All animals have names, but only dogs do tricks. Implement...
CodeCheck
Interfaces
87
Reversing the lines in a file
Code Completion
Your task is to read a file containing lines of text, and to write another file that contains these lines...
CodeCheck
Input and Output
88
Find longest word in file
Code Completion
Your task is to open a file, read all words in the file, and find the longest word in the...
CodeCheck
Input and Output
89
Throw IllegalArgumentException in SavingsAccount constructor
Code Completion
The SavingsAccount class given below is similar to that of Chapter 9. It should be illegal to construct savings accounts...
CodeCheck
Input and Output
90
Catching a NumberFormatException
Code Completion
In the following code, catch the NumberFormatException that is thrown when the argument of Integer.parseInt does not represent a number.
CodeCheck
Input and Output
91
Add throws clause to web reader
Code Completion
The checkURL method below checks whether a web site contains data. Checked exceptions can be thrown in the code. Your...
CodeCheck
Input and Output
92
Processing exam scores
Code Completion
Your task is to read a file containing exam scores, and to write another file that contains the results of...
CodeCheck
Input and Output
93
Processing names
Code Completion
Your task is to read an input file containing a name on each line, and then write an output file...
CodeCheck
Input and Output
94
Converting temperatures
Code Completion
Your task is to read an input file containing a month name followed by the average maximum temperature for that...
CodeCheck
Input and Output
95
Throw IllegalArgumentException in Vehicle constructor
Code Completion
The Vehicle class given below is used to represent various types of self-propelled vehicles. It should be illegal to construct...
CodeCheck
Input and Output
96
Design IllegalNumberOfWheels Exception
Code Completion
The following Vehicle class throws a custom exception of type IllegalNumberOfWheels. Your task is to implement this exception class. The...
CodeCheck
Input and Output
97
SuperCaesar Cipher
Code Completion
The SuperCaesar cipher is just like the Caesar cipher, except that the key value is incremented in each step. For...
CodeCheck
Advanced Input and Output
98
HyperCaesar cipher
Code Completion
The HyperCaesar cipher is just like the Caesar cipher, except that the key for each step is the initial key...
CodeCheck
Advanced Input and Output
99
Swap As and Os in RandomAccessFile
Code Completion
Your task is to swap all letters A with O and all letters a with o in a RandomAccessFile. Simply...
CodeCheck
Advanced Input and Output
100
Swap adjacent characters in a RandomAccessFile
Code Completion
Your task is to swap adjacent letters in a RandomAccessFile. Simply read two bytes, back up by two bytes, and...
CodeCheck
Advanced Input and Output
101
Reading a serialized array of objects
Code Completion
Your task is to read a serialized array of objects. You are given a FileInputStream, and you need to read...
CodeCheck
Advanced Input and Output
102
Remove short words
Code Completion
Your task is to remove all short words (that is, words with at most 3 characters) from a linked list.
CodeCheck
Linear Data Structures
103
Duplicate short words
Code Completion
Your task is to duplicate all short words (that is, words with at most 3 characters) in a linked list....
CodeCheck
Linear Data Structures
104
Concatenate elements backwards
Code Completion
Your task is to concatenate all elements in a linked list of strings backwards, starting at the end of the...
CodeCheck
Linear Data Structures
105
Rotate linked list by manipulating nodes
Code Completion
Your task is to add a rotate method to the LinkedList class of Section 15.2 that rotates the elements of...
CodeCheck
Linear Data Structures
106
Using a stack for checking balanced parentheses
Code Completion
A stack can be used to check whether an arithmetic expression such as
CodeCheck
Linear Data Structures
107
Remove all but first two elements from linked list
Code Completion
Write a method that removes all but the first two elements from a linked list, using an iterator. You may...
CodeCheck
Linear Data Structures
108
Add an element to the front and back of a linked list
Code Completion
Implement a method that adds an element to the beginning of a linked list and another at the end.
CodeCheck
Linear Data Structures
109
Add an element after the first and before the last
Code Completion
Write a method that adds an element after the first and another before the last element of a nonempty linked...
CodeCheck
Linear Data Structures
110
Implement addLast using raw nodes
Code Completion
Implement the addLast method in this simplified LinkedList class.
CodeCheck
Linear Data Structures
111
Palindrome testing with stack and queue
Code Completion
Using a queue and a stack, implement a method that tests whether a sequence of numbers is a palindrome, that...
CodeCheck
Linear Data Structures
112
GetVowels
Code Completion
Your task is to write a method getVowels that gets the vowels in a string. For example, the call getVowels("Hello,...
CodeCheck
Loops
113
EvenSum
Code Completion
Your task is to write a method evenSum that computes the sum of all even numbers between two given numbers....
CodeCheck
Loops
114
Stutter
Code Completion
Your task is to write a method stutter that repeats all letters t in a string. For example, the call...
CodeCheck
Loops
115
Count perfect squares
Code Completion
Your task is to write a method countPerfectSquares that counts all perfect squares in a given range. For example, the...
CodeCheck
Loops
116
Count Sevens
Code Completion
Your task is to write a method countSevens that counts the number of digits equal to 7 in a given...
CodeCheck
Loops
117
Format Phone Number
Code Completion
When people enter their telephone numbers into a form they use many different formats. Some examples are:
CodeCheck
Loops
118
Color codes for double-sized image
Code Completion
Consider an image that is composed of a number of colored small squares, each colored in one of these 8...
CodeCheck
Loops
119
Run-Length Encoding
Code Completion
A simple technique for compressing an image is run-length encoding. The color of each pixel or area is specified for...
CodeCheck
Loops
120
Picture of Colored Boxes
Code Completion
Your task is to write a method that produces images from strings describing color values.
CodeCheck
Loops
121
Balloon Filled Sky
Code Completion
Your task is to draw n balloons centered at random positions, each with a randomly colored circle and a white...
CodeCheck
Loops
122
Oracle client
Code Completion
Your task is to connect to the oracle server at port 7777 on the local host. The oracle protocol is...
CodeCheck
Networking
123
Oracle server
Code Completion
Your task is to provide an oracle server at port 7777 on the local host. The oracle protocol is very...
CodeCheck
Networking
124
Cookies with raw sockets
Code Completion
Many web site instruct browsers to set cookies, small pieces of information that the browser will send back to the...
CodeCheck
Networking
125
Cookies with URLConnection
Code Completion
Many web site instruct browsers to set cookies, small pieces of information that the browser will send back to the...
CodeCheck
Networking
126
Popular boys and girls names
Code Completion
The web sites http://www.census.gov/genealogy/names/dist.male.first and http://www.census.gov/genealogy/names/dist.female.first contain baby names sorted by popularity. The format is very simple: name, frequency, cumulative...
CodeCheck
Networking
127
371t3 hack3rs
Code Completion
The "elite hackers" like to make their text look cool by replacing characters with similar-looking symbols: e becomes 3, i...
CodeCheck
Objects
128
Average word length
Code Completion
Complete the following program to compute the average length of the words. Invoke the appropriate method to compute the length...
CodeCheck
Objects
129
Rectangle construction
Code Completion
Your task is to construct a rectangle with area 51.
CodeCheck
Objects
130
Translate square so that intersection has area 10
Code Completion
Your task is to translate the rectangle box2 in the program below so that the intersection of box and box2...
CodeCheck
Objects
131
Red checkerboard squares
Code Completion
Your task is to draw a simple checkerboard pattern.
CodeCheck
Objects
132
Traffic light
Code Completion
Your task is to draw the lamps in a traffic light.
CodeCheck
Objects
133
Make stronger password
Code Completion
A stronger password can be created by replacing characters with similar-looking symbols: e becomes 3, i becomes 1, a becomes...
CodeCheck
Objects
134
Reversing a string with StringBuilder
Code Completion
StringBuilder is another class that provides methods to manipulate strings. Look in the StringBuilder class API for information on the...
CodeCheck
Objects
135
Uppercase international letters
Code Completion
Your task is to find out what happens when you call the toUpperCase method on strings that contain accented characters...
CodeCheck
Objects
136
Draw intersection of rectangles
Code Completion
Draw two intersecting rectangles and color their intersection black.
CodeCheck
Objects
137
Rectangle with 3D effect
Code Completion
Complete the ThreeDButtonComponent class to draw a button with shading. The button is a Rectangle, with very thin rectangles on...
CodeCheck
Objects
138
Drawing with fill3DRect
Code Completion
Complete the ThreeButtonComponent class to draw three boxes that look like push buttons. Each box is a Rectangle drawn in...
CodeCheck
Objects
139
Using inheritance for modeling Square class
Code Completion
Intuitively, every square is a rectangle, so it is tempting to use inheritance for implementing a square:
CodeCheck
Object-Oriented Design
140
Using aggregation for modeling Square class
Code Completion
Intuitively, every square is a rectangle, so it is tempting to use inheritance for implementing a square:
CodeCheck
Object-Oriented Design
141
Use Money interface in invoice program
Code Completion
The invoice program assumes that prices are given in dollar. Other currencies have different rules, and it makes sense to...
CodeCheck
Object-Oriented Design
142
Add transfer to ATM
Code Completion
Add the capability of transferring money from the currently selected account to the other account from the same account holder...
CodeCheck
Object-Oriented Design
143
Add user interface for balance transfer
Code Completion
In this assignment, a transfer method has been added to the ATM class of section 12.5:
CodeCheck
Object-Oriented Design
144
Collaborator classes
Code Completion
In some situations, a class needs the help of other classes to complete a task. These other classes are called...
CodeCheck
Object-Oriented Design
145
Using Aggegation
Code Completion
A team has players. Use aggregation to complete the class constructor and the listTeam and addPlayer methods of the Team...
CodeCheck
Object-Oriented Design
146
Relationships between classes and interfaces
Code Completion
A stamp has a descriptive name, a face value, and an issuing country. Stamps have a measurable value (the face...
CodeCheck
Object-Oriented Design
147
Pyramid volume
Code Completion
A pyramid is built by stacking up cubes:
CodeCheck
Recursion
148
Zipper words
Code Completion
Two strings of equal length can be interlaced like the teeth of a zipper to form a new word. For...
CodeCheck
Recursion
149
Zipper words with helper method
Code Completion
Two strings of equal length can be interlaced like the teeth of a zipper to form a new word. For...
CodeCheck
Recursion
150
ZipperWordGenerator
Code Completion
You are given two strings of equal length. Your task is to generate all zipper words that can be produced...
CodeCheck
Recursion
151
A recursive squid (square in diamond)
Code Completion
A recursive squid is a square in a diamond containing another squid.
CodeCheck
Recursion
152
Reverse an integer
Code Completion
We want to implement a method that reverses the digits in an integer. For example, reverseInt(3456) should yield 6543.
CodeCheck
Recursion
153
Reverse an integer with helper method
Code Completion
We want to implement a method that reverses the digits in an integer. For example, reverseDigits(3456) should yield 6543.
CodeCheck
Recursion
154
Multiplication as recursive addition
Code Completion
Complete the multiply method in the MyMethods class so that it returns the product of the non-negative integer n multipled...
CodeCheck
Recursion
155
Recursive toString for array
Code Completion
Complete the static mkString method in the MyMethods class so that it formats an array of int values, with the...
CodeCheck
Recursion
156
Reverse toString for array
Code Completion
Complete the static toStringInReverse method in the MyMethods class so that it formats an array of int values in reverse...
CodeCheck
Recursion
157
Extract uppercase letters from string
Code Completion
Modify the static return upperCase method in the MyMethods class so that it returns a string of the upper case...
CodeCheck
Recursion
158
Recursive string reversal with helper method
Code Completion
Complete the static reverseHelper method so that the reverse method returns a String that is the reverse of the parameter...
CodeCheck
Recursion
159
Find vowels in string with recursive helper method
Code Completion
Complete the MyMethods class so that the static vowels method returns a string of the vowels of the string parameter....
CodeCheck
Recursion
160
Modified SelectionSort
Code Completion
Your task is to modify the selection sort algorithm so that you find the largest element and swap it to...
CodeCheck
Sorting and Searching
161
Count visits in selection sort
Code Completion
In section 14.3, we approximated a count of the array visits in selection sort. Your task is to provide an...
CodeCheck
Sorting and Searching
162
Count visits in selection sort
Code Completion
In section 14.5, we approximated a count of the array visits in merge sort. Your task is to provide an...
CodeCheck
Sorting and Searching
163
Sort real data
Code Completion
Your task is to sort an array list of path names such as
CodeCheck
Sorting and Searching
164
Number guesser
Code Completion
Your task is to implement a number guesser that works on the principle of a binary search. In each step,...
CodeCheck
Sorting and Searching
165
Selection sort modification placing only min and max
Code Completion
Your task is to modify the selection sort algorithm so that you find the largest element and swap it to...
CodeCheck
Sorting and Searching
166
Selection sort modification placing even before odd
Code Completion
Implement a modification of the SelectionSorter class that reorders the array to have even elements followed by odd ones. Follow...
CodeCheck
Sorting and Searching
167
Merge sort modification placing even before odd
Code Completion
Modify the merge sort algorithm so that, instead of sorting an array, it rearranges places all even elements before the...
CodeCheck
Sorting and Searching
168
Descending merge sort
Code Completion
CodeCheck
Sorting and Searching
169
Selection sort modification, placing the largest element first
Code Completion
Your task is to modify the selection sort algorithm so that you find the largest element and swap it to...
CodeCheck
Sorting and Searching
170
Letter set
Code Completion
Your task is to produce a set of all letters in a string. Letters are represented as strings of length...
CodeCheck
Tree Structures
171
Letter frequency map
Code Completion
Your task is to produce a map of the frequencies of all letters in a string. Letters are represented as...
CodeCheck
Tree Structures
172
Path lengths in binary tree
Code Completion
Your task is to compute a set of all path lengths in a binary tree. For example, given this tree,
CodeCheck
Tree Structures
173
Hash code for LabeledPoint
Code Completion
Implement the hashCode method for the LabeledPoint class so that equal objects have the same hash code and that unequal...
CodeCheck
Tree Structures
174
A fast priority queue
Code Completion
It is possible to provide a fast priority queue implementation if the inserted items have a bounded number of integer...
CodeCheck
Tree Structures
175
Unique words in two string sets
Code Completion
Implement a method that receives two arrays of strings and determines which words are unique to each.
CodeCheck
Tree Structures
176
Map words to their lengths
Code Completion
Given an array of strings, create a tree map with each string as a key and its corresponding value the...
CodeCheck
Tree Structures
177
Map word lengths to words
Code Completion
Given an array of strings, create a tree map whose keys are the string lengths and whose values are the...
CodeCheck
Tree Structures
178
Hash code for Person class
Code Completion
When you add instances of the given Person class in a HashSet, the resulting hash set is too large. Evidently,...
CodeCheck
Tree Structures
179
Make Person class comparable
Code Completion
The program below will fail to run because the Person class does not implement the Comparable interface. Modify the class...
CodeCheck
Tree Structures
180
Read XML from string or file.
Code Completion
You are given a string that is either valid XML (when it starts with a '<' character) or the name...
CodeCheck
XML
181
How many items in this RSS file?
Code Completion
An RSS file contains a sequence of item elements inside a channel element. Here is a sample RSS file:
CodeCheck
XML
182
Get a title from an RSS file
Code Completion
An RSS file contains a sequence of item elements inside a channel element. Here is a sample RSS file:
CodeCheck
XML
183
Get the version attribute from an RSS file
Code Completion
An RSS file describes a set of news items. Here is a sample RSS file:
CodeCheck
XML
184
Get the version attribute from an RSS file
Code Completion
An RSS file describes a set of news items. Here is a sample RSS file:
CodeCheck
XML
185
Given a two-dimensional array of integers, return the average of the four corner elements.
Code Completion
Given a two-dimensional array of integers, return the average of the four corner elements.
CodeCheck
Two-Dimensional Arrays
,
No Loops
186
Given a two-dimensional array of integers, return the middle element if both the row and column lenghts are odd, or the average of the two or four middle elements of one or both is even.
Code Completion
Given a two-dimensional array of integers, return the middle element if both the row and column lenghts are odd, or...
CodeCheck
Two-Dimensional Arrays
,
No Loops
187
Given a two-dimensional array of integers and a string N, E, S, W, give the middle element along the border in the given compass direction, or the average of the two middle ones if the border length is even.
Code Completion
Given a two-dimensional array of integers and a string N, E, S, W, give the middle element along the border...
CodeCheck
Two-Dimensional Arrays
,
No Loops
188
Given a two-dimensional array of integers and a string NW, NW, SW, SE, return the sum of the four elements in the given compass direction.
Code Completion
Given a two-dimensional array of integers and a string NW, NW, SW, SE, return the sum of the four elements...
CodeCheck
Two-Dimensional Arrays
,
No Loops
189
Given a two-dimensional array of integers, row/column indexes r, c, and a string N E S W, return the neighbor in that direction, or 0 if it doesn't exist.
Code Completion
Given a two-dimensional array of integers, row/column indexes r, c, and a string N E S W, return the neighbor...
CodeCheck
Two-Dimensional Arrays
,
No Loops
190
Repeat with NW NE SW SE.
Code Completion
Repeat with NW NE SW SE.
CodeCheck
Two-Dimensional Arrays
,
No Loops
191
Given a two-dimensional array of integers and row/column indexes r, c, return the number of neighbors (not counting the element itself).
Code Completion
Given a two-dimensional array of integers and row/column indexes r, c, return the number of neighbors (not counting the element...
CodeCheck
Two-Dimensional Arrays
,
No Loops
192
On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, positions are marked with a letter between a and h for the column and a number between...
CodeCheck
Two-Dimensional Arrays
,
No Loops
193
Given an array of integers of length ≥ 4, return the average of the first two and last two elements.
Code Completion
Given an array of integers of length ≥ 4, return the average of the first two and last two elements.
CodeCheck
Arrays - Simple Exercises
,
No loops
194
Given an array of integers of length ≥ 3, return the average of the first, last, and middle element (or the two middle elements if the length is even).
Code Completion
Given an array of integers of length ≥ 3, return the average of the first, last, and middle element (or...
CodeCheck
Arrays - Simple Exercises
,
No loops
195
Given an array of integers, swap the first and last elements.
Code Completion
Given an array of integers, swap the first and last elements.
CodeCheck
Arrays - Simple Exercises
,
No loops
196
Given an array of integers, swap the first two and the last two elements.
Code Completion
Given an array of integers, swap the first two and the last two elements.
CodeCheck
Arrays - Simple Exercises
,
No loops
197
Given an input string, print the string with the first and last letter removed if they were equal, or the original string if they were not.
Code Completion
Given an input string, print the string with the first and last letter removed if they were equal, or the...
CodeCheck
Branches
,
Branches Without Functions
198
Given an actual time and an alarm clock time, both in “military” format (such as 0730 for 7:30am), print how many more minutes before the alarm rings.
Code Completion
Given an actual time and an alarm clock time, both in “military” format (such as 0730 for 7:30am), print how...
CodeCheck
Branches
,
Branches Without Functions
199
Repeat the preceding exercise for U.
Code Completion
Repeat the preceding exercise for U.S. time (e.g. 7:30am).
CodeCheck
Branches
,
Branches Without Functions
200
Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neigboring lattice point.
Code Completion
Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neigboring lattice...
CodeCheck
Branches
,
Branches Without Functions
201
Repeat with compass directions NW, NE, SW, SE.
Code Completion
Repeat with compass directions NW, NE, SW, SE.
CodeCheck
Branches
,
Branches Without Functions
202
On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, positions are marked with a letter between a and h for the column and a number between...
CodeCheck
Branches
,
Branches Without Functions
203
On a chessboard, fields are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, fields are marked with a letter between a and h for the column and a number between...
CodeCheck
Branches
,
Branches Without Functions
204
Given the x- and y-coordinates of a point, print whether the point lies in the first, second, third, or fourth quadrant plane, or on the x-axis, or on the y-axis, or the origin.
Code Completion
Given the x- and y-coordinates of a point, print whether the point lies in the first, second, third, or fourth...
CodeCheck
Branches
,
Branches Without Functions
205
Given three numbers x, y, z, determine if one of them is the sum of the two others, and then print out the equation.
Code Completion
Given three numbers x, y, z, determine if one of them is the sum of the two others, and then...
CodeCheck
Branches
,
Branches Without Functions
206
Given three numbers x, y, z, print out how whether they are all distinct, two are the same, or all three are the same.
Code Completion
Given three numbers x, y, z, print out how whether they are all distinct, two are the same, or all...
CodeCheck
Branches
,
Branches Without Functions
207
Given two integers x and y, print their sum, but if it is more than 100 or less than 0, print "out of range".
Code Completion
Given two integers x and y, print their sum, but if it is more than 100 or less than 0,...
CodeCheck
Branches
,
Branches Without Functions
208
Given three integers x, y, z, print the sum of the odd integers.
Code Completion
Given three integers x, y, z, print the sum of the odd integers.
CodeCheck
Branches
,
Branches Without Functions
209
Given three input strings, print all but the shortest one.
Code Completion
Given three input strings, print all but the shortest one.
CodeCheck
Branches
,
Branches Without Functions
210
Given a two-dimensional array of integers, return the number of distinct elements.
Code Completion
Given a two-dimensional array of integers, return the number of distinct elements.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
211
Given a two-dimensional array of integers, remove any adjacent duplicate rows by filling the duplicates with zeroes.
Code Completion
Given a two-dimensional array of integers, remove any adjacent duplicate rows by filling the duplicates with zeroes.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
212
Given a two-dimensional array of integers, return the index of the first row that is entirely filled with zeroes.
Code Completion
Given a two-dimensional array of integers, return the index of the first row that is entirely filled with zeroes.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
213
Given a two-dimensional array of integers, return the index of the first row that is entirely filled with zeroes.
Code Completion
Given a two-dimensional array of integers, return the index of the first row that is entirely filled with zeroes. <
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
214
Given a two-dimensional array of integers, return the position of the largest square subarray filled with zeroes, as an array of length 2.
Code Completion
Given a two-dimensional array of integers, return the position of the largest square subarray filled with zeroes, as an array...
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
215
Repeat the previous exercise with subarrays that are not necessarily square.
Code Completion
Repeat the previous exercise with subarrays that are not necessarily square.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
216
Given an array of integers, count how many elements are negative.
Code Completion
Given an array of integers, count how many elements are negative.
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
217
Given an array a, count how many times the ith element from the front equals the ith element from the back.
Code Completion
Given an array a, count how many times the ith element from the front equals the ith element from the...
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
218
Given an array of integers and two values a and b, count how many elements are at least a and at most b.
Code Completion
Given an array of integers and two values a and b, count how many elements are at least a and...
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
219
Given an array of integers, return the most frequent element.
Code Completion
Given an array of integers, return the most frequent element. If there is more than one element with maximum frequency,...
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
220
Given an array of integers, return an array of all elements that occur with maximum frequency.
Code Completion
Given an array of integers, return an array of all elements that occur with maximum frequency.
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
221
Given an array of integers, return the position of the first element that occurs more than once, or -1 if all elements occur exactly once.
Code Completion
Given an array of integers, return the position of the first element that occurs more than once, or -1 if...
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
222
Given an array of integers, return an array of all elements that occur exactly once.
Code Completion
Given an array of integers, return an array of all elements that occur exactly once.
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
223
Given an array of integers, remove all elements that occur more than once, leaving the first occurrence.
Code Completion
Given an array of integers, remove all elements that occur more than once, leaving the first occurrence.
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
224
Given two arrays of integers a and b of the same length, count the number of positions where the arrays have the same elements.
Code Completion
Given two arrays of integers a and b of the same length, count the number of positions where the arrays...
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
225
Given two arrays of integers a and b of the same length, count the number of positions where the array elements differ by at least 2.
Code Completion
Given two arrays of integers a and b of the same length, count the number of positions where the array...
CodeCheck
Arrays - Simple Exercises
,
Counting Elements
226
Given two arrays a and b, remove all elements of b from a.
Code Completion
Given two arrays a and b, remove all elements of b from a.
CodeCheck
Arrays - Simple Exercises
,
Double Loops
227
Given two arrays a and b, return an array that contains all elements occurring in a but not in b.
Code Completion
Given two arrays a and b, return an array that contains all elements occurring in a but not in b.
CodeCheck
Arrays - Simple Exercises
,
Double Loops
228
Given an array a, return the longest n so that the first n elements equal the last n elements.
Code Completion
Given an array a, return the longest n so that the first n elements equal the last n elements.
CodeCheck
Arrays - Simple Exercises
,
Double Loops
229
Given an array of integers, return the largest sum of consecutive elements.
Code Completion
Given an array of integers, return the largest sum of consecutive elements.
CodeCheck
Arrays - Simple Exercises
,
Double Loops
230
Given an array of integers, return the largest sequence whose reverse also occurs somewhere in the array.
Code Completion
Given an array of integers, return the largest sequence whose reverse also occurs somewhere in the array.
CodeCheck
Arrays - Simple Exercises
,
Double Loops
231
Given an array a of integers, return an array of all elements of a that occur exactly once.
Code Completion
Given an array a of integers, return an array of all elements of a that occur exactly once.
CodeCheck
Arrays - Simple Exercises
,
Double Loops
232
Given an array of integers, return an array of arrays of length 2, containing each unique element together with its frequency.
Code Completion
Given an array of integers, return an array of arrays of length 2, containing each unique element together with its...
CodeCheck
Arrays - Simple Exercises
,
Double Loops
233
Given an array of integers, return the position of the longest subsequence of consecutive integers a, a + 1, a + 2, .
Code Completion
Given an array of integers, return the position of the longest subsequence of consecutive integers a, a + 1, a...
CodeCheck
Arrays - Simple Exercises
,
Double Loops
234
Given an integer n, fill an array of length n with 1 -1 1 -1 .
Code Completion
Given an integer n, fill an array of length n with 1 -1 1 -1 ...
CodeCheck
Arrays - Simple Exercises
,
Filling
235
Given integers n and k, fill an array of length n with 0 1 2 .
Code Completion
Given integers n and k, fill an array of length n with 0 1 2 ... k-1 0 1 2...
CodeCheck
Arrays - Simple Exercises
,
Filling
236
Given integers a and b, fill an array with a, a + 1, a + 2, .
Code Completion
Given integers a and b, fill an array with a, a + 1, a + 2, ..., b.
CodeCheck
Arrays - Simple Exercises
,
Filling
237
Given integers a and b, fill an array containing all even numbers that are at least a and at most b.
Code Completion
Given integers a and b, fill an array containing all even numbers that are at least a and at most...
CodeCheck
Arrays - Simple Exercises
,
Filling
238
Given an integer n, fill an array with 1 2 2 3 3 3 4 4 4 4 .
Code Completion
Given an integer n, fill an array with 1 2 2 3 3 3 4 4 4 4 ... and...
CodeCheck
Arrays - Simple Exercises
,
Filling
239
Given an array of integers and a value, return the position of the last occurrence of the value in the array, or -1 if the value does not exist.
Code Completion
Given an array of integers and a value, return the position of the last occurrence of the value in the...
CodeCheck
Arrays - Simple Exercises
,
Finding Elements
240
Given an array of integers and a value, return the difference between the last and first position of the value in the array, or -1 if the value does not exist.
Code Completion
Given an array of integers and a value, return the difference between the last and first position of the value...
CodeCheck
Arrays - Simple Exercises
,
Finding Elements
241
Given an array of integers and a value, fill an array with all positions of the value in the array.
Code Completion
Given an array of integers and a value, fill an array with all positions of the value in the array.
CodeCheck
Arrays - Simple Exercises
,
Finding Elements
242
Given an array of integers and a value, return the position of the element that is closest to the value.
Code Completion
Given an array of integers and a value, return the position of the element that is closest to the value....
CodeCheck
Arrays - Simple Exercises
,
Finding Elements
243
Given two arrays of integers of the same length, return the first position where their elements are the same.
Code Completion
Given two arrays of integers of the same length, return the first position where their elements are the same.
CodeCheck
Arrays - Simple Exercises
,
Finding Elements
244
Given two arrays of integers of the same length, return the first position where their elements differ.
Code Completion
Given two arrays of integers of the same length, return the first position where their elements differ.
CodeCheck
Arrays - Simple Exercises
,
Finding Elements
245
Given two numbers, return true if they both have the same sign.
Code Completion
Given two numbers, return true if they both have the same sign.
CodeCheck
Branches
,
Branches with Functions
246
Write a function that checks whether two points with coordinates x1, y1 and x2, y2 are in the same quadrant.
Code Completion
Write a function that checks whether two points with coordinates x1, y1 and x2, y2 are in the same quadrant.
CodeCheck
Branches
,
Branches with Functions
247
Given two numbers, return their distance if it less than 10, or 10 otherwise.
Code Completion
Given two numbers, return their distance if it less than 10, or 10 otherwise.
CodeCheck
Branches
,
Branches with Functions
248
On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, positions are marked with a letter between a and h for the column and a number between...
CodeCheck
Branches
,
Branches with Functions
249
Given three numbers x, y, z and a Boolean variable <code>strict</code>, return <code>true</code> if <code>strict</code> is false and x ≤ y ≤ z, or <code>strict</code> is true and x < y < z.
Code Completion
Given three numbers x, y, z and a Boolean variable
strict
, return
true
if
strict
is false and x ≤...
CodeCheck
Branches
,
Branches with Functions
250
Given four numbers a, b, c, d, return true if exactly two of them are the same.
Code Completion
Given four numbers a, b, c, d, return true if exactly two of them are the same.
CodeCheck
Branches
,
Branches with Functions
251
Given three numbers, return true if they are evenly spaced; that is, sorted in ascending or descending order, with the same distance between them.
Code Completion
Given three numbers, return true if they are evenly spaced; that is, sorted in ascending or descending order, with the...
CodeCheck
Branches
,
Branches with Functions
252
Repeat for four numbers.
Code Completion
Repeat for four numbers. Hint: Use the previous problem.
CodeCheck
Branches
,
Branches with Functions
253
Given numbers x, y, and target, return whichever of x and y is closer to the target.
Code Completion
Given numbers x, y, and target, return whichever of x and y is closer to the target. If they have...
CodeCheck
Branches
,
Branches with Functions
254
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N E S W.
Code Completion
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
255
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N E S W NE NW SE SW.
Code Completion
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
256
Given a two-dimensional array of integers and row/column positions r, c, return the compass direction of the largest neighbor as a string N E S W NE NW SE SW.
Code Completion
Given a two-dimensional array of integers and row/column positions r, c, return the compass direction of the largest neighbor as...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
257
Given a two-dimensional array of integers, row/column positions r, c, and a value x, fill the given element and its neighbors in the compass directions N E S W NE NW SE SW with x.
Code Completion
Given a two-dimensional array of integers, row/column positions r, c, and a value x, fill the given element and its...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
258
Given a two-dimensional array a of integers and row/column positions r, c, return a 3x3 array whose middle element is a[r][c], and whose neighbors are copied from the original.
Code Completion
Given a two-dimensional array a of integers and row/column positions r, c, return a 3x3 array whose middle element is...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
259
Given a two-dimensional array of integers, compute the sum of all positive elements.
Code Completion
Given a two-dimensional array of integers, compute the sum of all positive elements.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
260
Given a two-dimensional array of integers, return the largest element in the array.
Code Completion
Given a two-dimensional array of integers, return the largest element in the array.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
261
Given a two-dimensional array of integers, return the position of the smallest element in the array as an array of length 2.
Code Completion
Given a two-dimensional array of integers, return the position of the smallest element in the array as an array of...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
262
Given a two-dimensional array of integers and a value x, return the position of the first match as an array of length 2.
Code Completion
Given a two-dimensional array of integers and a value x, return the position of the first match as an array...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
263
Given a two-dimensional array of integers and a value x, return the positions of all matching elements, as an array of arrays of length 2.
Code Completion
Given a two-dimensional array of integers and a value x, return the positions of all matching elements, as an array...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
264
Given a two-dimensional array of integers, compute the sum of all elements that are not one of the borders.
Code Completion
Given a two-dimensional array of integers, compute the sum of all elements that are not one of the borders.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
265
Given a two-dimensional square array of integers, compute the sum of all elements that are not on one of the diagonals.
Code Completion
Given a two-dimensional square array of integers, compute the sum of all elements that are not on one of the...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
266
Given a two-dimensional array of integers, replace all negative elements with zero.
Code Completion
Given a two-dimensional array of integers, replace all negative elements with zero.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
267
Given a two-dimensional array of integers, reverse all rows.
Code Completion
Given a two-dimensional array of integers, reverse all rows.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
268
Given a two-dimensional array of integers, shift each row by one to the right and put a 0 at the leftmost column.
Code Completion
Given a two-dimensional array of integers, shift each row by one to the right and put a 0 at the...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
269
Given an r x c array of integers, return an (r + 2) x (c + 2) array whose borders are zero and whose interior is the original array.
Code Completion
Given an r x c array of integers, return an (r + 2) x (c + 2) array whose borders...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
270
Given a two-dimensional array of integers, return an array of the largest element in each row.
Code Completion
Given a two-dimensional array of integers, return an array of the largest element in each row.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
271
Given a two-dimensional array of integers, return an array of the number of negative elements in each column.
Code Completion
Given a two-dimensional array of integers, return an array of the number of negative elements in each column.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
272
Given a two-dimensional array of integers and a row index, return the largest element in that row.
Code Completion
Given a two-dimensional array of integers and a row index, return the largest element in that row.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
273
Given a two-dimensional array of integers and a row index r, reverse the given row.
Code Completion
Given a two-dimensional array of integers and a row index r, reverse the given row.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
274
Given a two-dimensional square array of integers, reverse both diagonals.
Code Completion
Given a two-dimensional square array of integers, reverse both diagonals.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
275
Given a two-dimensional array of integers and a column index, return the smallest element in that column.
Code Completion
Given a two-dimensional array of integers and a column index, return the smallest element in that column.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
276
Given a two-dimensional array of integers, an index, and a string R or C, return the sum of the elements in that row or column.
Code Completion
Given a two-dimensional array of integers, an index, and a string R or C, return the sum of the elements...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
277
Given a two-dimensional array of integers, a row index r, and a column index c, return the sum of all elements in the given row and column.
Code Completion
Given a two-dimensional array of integers, a row index r, and a column index c, return the sum of all...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
278
Given a two-dimensional array of integers and a string N, E, S, W, return the sum of all elements of the border in the given compass direction.
Code Completion
Given a two-dimensional array of integers and a string N, E, S, W, return the sum of all elements of...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
279
Given a two-dimensional array of integers, return the sum of all elements along the north and south border.
Code Completion
Given a two-dimensional array of integers, return the sum of all elements along the north and south border.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
280
Given a two-dimensional array of integers, return the sum of all elements along all borders but not the corners.
Code Completion
Given a two-dimensional array of integers, return the sum of all elements along all borders but not the corners.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
281
Given a two-dimensional array of integers, return the sum of all elements along all borders including the corners.
Code Completion
Given a two-dimensional array of integers, return the sum of all elements along all borders including the corners.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
282
Given a two-dimensional square array of integers, return the sum of the elements along both diagonals.
Code Completion
Given a two-dimensional square array of integers, return the sum of the elements along both diagonals. Make sure not to...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
283
Given an array of integers, return the position of the first occurrence of the largest element.
Code Completion
Given an array of integers, return the position of the first occurrence of the largest element.
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
284
Given an array of integers, return the position of the last occurrence of the largest element.
Code Completion
Given an array of integers, return the position of the last occurrence of the largest element.
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
285
Given an array of integers, return the difference of the positions of the first and the last occurrence of the largest element.
Code Completion
Given an array of integers, return the difference of the positions of the first and the last occurrence of the...
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
286
Given an array of integers, return the difference between the maximum and minimum.
Code Completion
Given an array of integers, return the difference between the maximum and minimum.
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
287
Given an array of integers, swap the the maximum and minimum.
Code Completion
Given an array of integers, swap the the maximum and minimum.
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
288
Given an array of integers, return the second-largest element.
Code Completion
Given an array of integers, return the second-largest element.
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
289
Given an array of element, find the shortest distance between two consecutive elements.
Code Completion
Given an array of element, find the shortest distance between two consecutive elements.
CodeCheck
Arrays - Simple Exercises
,
Maximum and Minimum
290
Given an array of integers and an integer n, remove all elementts > n or < -n.
Code Completion
Given an array of integers and an integer n, remove all elementts > n or < -n. Shift all remaining...
CodeCheck
Arrays - Simple Exercises
,
Moving or Removing Elements
291
Given an array of integers, move all zeroes to the back.
Code Completion
Given an array of integers, move all zeroes to the back.
CodeCheck
Arrays - Simple Exercises
,
Moving or Removing Elements
292
Given an array of integers, move all zeroes to the front.
Code Completion
Given an array of integers, move all zeroes to the front.
CodeCheck
Arrays - Simple Exercises
,
Moving or Removing Elements
293
Given an array of integers, move all negative numbers to the front and all positive numbers to the back, keeping their relative order.
Code Completion
Given an array of integers, move all negative numbers to the front and all positive numbers to the back, keeping...
CodeCheck
Arrays - Simple Exercises
,
Moving or Removing Elements
294
Given an array of integers, remove all even elements that occur exactly twice.
Code Completion
Given an array of integers, remove all even elements that occur exactly twice.
CodeCheck
Arrays - Simple Exercises
,
Moving or Removing Elements
295
Given an array of integers, remove all adjacent duplicates.
Code Completion
Given an array of integers, remove all adjacent duplicates.
CodeCheck
Arrays - Simple Exercises
,
Moving or Removing Elements
296
Given a string s and an integer n, return a string in which each of the characters in s is repeated n times.
Code Completion
Given a string s and an integer n, return a string in which each of the characters in s is...
CodeCheck
Strings
,
Other String Operations
297
Given a string s, return the first vowel that is doubled in the string.
Code Completion
Given a string s, return the first vowel that is doubled in the string.
CodeCheck
Strings
,
Other String Operations
298
Given a string s, return the string with adjacent duplicates removed.
Code Completion
Given a string s, return the string with adjacent duplicates removed. For example, Mississippi yields Misisipi.
CodeCheck
Strings
,
Other String Operations
299
Given a string s and a string t, return a string in which all the characters of s that occur in t have been replaced by a _ sign.
Code Completion
Given a string s and a string t, return a string in which all the characters of s that occur...
CodeCheck
Strings
,
Other String Operations
300
Given a string, return a string composed first of all characters at even positions and then of all characters at odd positions.
Code Completion
Given a string, return a string composed first of all characters at even positions and then of all characters at...
CodeCheck
Strings
,
Other String Operations
301
Write a method that undoes the effect of the preceding exercise.
Code Completion
Write a method that undoes the effect of the preceding exercise.
CodeCheck
Strings
,
Other String Operations
302
Given a string and two characters x and y, interchange all occurrences of x and y.
Code Completion
Given a string and two characters x and y, interchange all occurrences of x and y.
CodeCheck
Strings
,
Other String Operations
303
Given a string s and a character c, return a string with the characters surrounding the first of c reversed.
Code Completion
Given a string s and a character c, return a string with the characters surrounding the first of c reversed....
CodeCheck
Strings
,
Other String Operations
304
Given a string s and a character c, return a string with the characters surrounding any occurrence of c reversed.
Code Completion
Given a string s and a character c, return a string with the characters surrounding any occurrence of c reversed....
CodeCheck
Strings
,
Other String Operations
305
Given an integer n, produce the array <pre>0 1 2 3 .
Code Completion
Given an integer n, produce the array
0 1 2 3 ... n 1 2 3 4 ... 0 ......
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
306
Given two two-dimensional arrays a and b of integers with the same number of rows and columns, return an array of the same size where each element is the greater of the corresponding elements in the two arrays.
Code Completion
Given two two-dimensional arrays a and b of integers with the same number of rows and columns, return an array...
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
307
Repeat the preceding exercise where the array dimensions need not match, filling positions that exist in neither array with 0.
Code Completion
Repeat the preceding exercise where the array dimensions need not match, filling positions that exist in neither array with 0.
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
308
Given two two-dimensional arrays of integers with the same number of rows and columns, return the first position where they do not match, as an array of length 2.
Code Completion
Given two two-dimensional arrays of integers with the same number of rows and columns, return the first position where they...
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
309
Given two two-dimensional arrays with the same number of rows, return an array that places them side by side.
Code Completion
Given two two-dimensional arrays with the same number of rows, return an array that places them side by side.
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
310
Repeat where the row lengths don't have to match.
Code Completion
Repeat where the row lengths don't have to match. Fill the shorter array with zeroes.
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
311
Given a two-dimensional array a, return an array whose [i][j] element is the average of the neighbors of a[i][j] in the N, E, S, W direction.
Code Completion
Given a two-dimensional array a, return an array whose [i][j] element is the average of the neighbors of a[i][j] in...
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
312
Given two strings s and t, return the first position where their characters differ, or -1 if they are identical.
Code Completion
Given two strings s and t, return the first position where their characters differ, or -1 if they are identical.
CodeCheck
Strings
,
Comparing Strings
313
Given two strings s and t, return the first position where their characters are the same, or -1 if there is no such position.
Code Completion
Given two strings s and t, return the first position where their characters are the same, or -1 if there...
CodeCheck
Strings
,
Comparing Strings
314
Given a string s, count how many times the ith character from the front equals the ith character from the back.
Code Completion
Given a string s, count how many times the ith character from the front equals the ith character from the...
CodeCheck
Strings
,
Comparing Strings
315
Given strings s and t, return a list of all positions in which t occurs in s.
Code Completion
Given strings s and t, return a list of all positions in which t occurs in s.
CodeCheck
Strings
,
Finding Substrings
316
Given strings s and t, return a string in which all occurrences of t are removed from s.
Code Completion
Given strings s and t, return a string in which all occurrences of t are removed from s.
CodeCheck
Strings
,
Finding Substrings
317
Given strings s and t, return a string in which all characters in t are removed from s.
Code Completion
Given strings s and t, return a string in which all characters in t are removed from s.
CodeCheck
Strings
,
Finding Substrings
318
Given a string s, return the longest prefix that is repeated somewhere else in the string.
Code Completion
Given a string s, return the longest prefix that is repeated somewhere else in the string.
CodeCheck
Strings
,
Finding Substrings
319
Given a string s, find the longest prefix that also occurs at the end (so that s = p + t + p), and return t, the string without the beginning and the end.
Code Completion
Given a string s, find the longest prefix that also occurs at the end (so that s = p +...
CodeCheck
Strings
,
Finding Substrings
320
Given a string, return the string with the first and last characters swapped.
Code Completion
Given a string, return the string with the first and last characters swapped.
CodeCheck
Strings
,
No Loops
321
Given a string, return the string with the middle two characters removed if it has even length, and the middle character removed if it has odd length.
Code Completion
Given a string, return the string with the middle two characters removed if it has even length, and the middle...
CodeCheck
Strings
,
No Loops
322
Given a string, return the string with the middle two characters swapped if it has even length, and the middle three characters swapped if it has odd length.
Code Completion
Given a string, return the string with the middle two characters swapped if it has even length, and the middle...
CodeCheck
Strings
,
No Loops
323
Given a string, return the string with the first and second half swapped.
Code Completion
Given a string, return the string with the first and second half swapped. If the string has odd length, leave...
CodeCheck
Strings
,
No Loops
324
Given a string, return the string with the first half and the second half doubled.
Code Completion
Given a string, return the string with the first half and the second half doubled. For example, Java becomes JaJavava...
CodeCheck
Strings
,
No Loops
325
Given a string, find the first integer inside and return its value as an integer.
Code Completion
Given a string, find the first integer inside and return its value as an integer. Return 0 if there is...
CodeCheck
Strings
,
Numbers in Strings
326
Given a string, find the sum of all integers inside.
Code Completion
Given a string, find the sum of all integers inside. Return 0 if there is no integer inside.
CodeCheck
Strings
,
Numbers in Strings
327
Given a string, find all integers inside and return a string that separates them by commas.
Code Completion
Given a string, find all integers inside and return a string that separates them by commas.
CodeCheck
Strings
,
Numbers in Strings
328
Given a string in which words are separated by spaces, return the longest word.
Code Completion
Given a string in which words are separated by spaces, return the longest word.
CodeCheck
Strings
,
Words
329
Given a string in which words are separated by spaces, return the first word that is duplicated (such as an accidental “this this”).
Code Completion
Given a string in which words are separated by spaces, return the first word that is duplicated (such as an...
CodeCheck
Strings
,
Words
330
Given a string in which words are separated by spaces, return the first word that is repeated somewhere in the string.
Code Completion
Given a string in which words are separated by spaces, return the first word that is repeated somewhere in the...
CodeCheck
Strings
,
Words
331
Given a string in which words are separated by spaces, and two words a and b, interchange all occurrences of a and b.
Code Completion
Given a string in which words are separated by spaces, and two words a and b, interchange all occurrences of...
CodeCheck
Strings
,
Words
332
Given an array of integers, return the sum of all positive elements.
Code Completion
Given an array of integers, return the sum of all positive elements.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
333
Given an array of integers, find the largest sum of two different elements in the array.
Code Completion
Given an array of integers, find the largest sum of two different elements in the array.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
334
Given an array of floating-point numbers, return an array of the averages of consecutive element pairs of the original array.
Code Completion
Given an array of floating-point numbers, return an array of the averages of consecutive element pairs of the original array.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
335
Given an array of integers and an integer n, return an array of the averages of n consecutive elements of the original array.
Code Completion
Given an array of integers and an integer n, return an array of the averages of n consecutive elements of...
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
336
Given an array of integers, return the average of all elements that are not the maximum or minimum.
Code Completion
Given an array of integers, return the average of all elements that are not the maximum or minimum.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
337
Given an array of integers, replace each element with the average of its neighbors.
Code Completion
Given an array of integers, replace each element with the average of its neighbors.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
338
Given an array of integers, return the sum of all odd elements.
Code Completion
Given an array of integers, return the sum of all odd elements.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
339
Given an array of integers and two values a and b, return the sum of all elements that are at least a and at most b.
Code Completion
Given an array of integers and two values a and b, return the sum of all elements that are at...
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
340
Given an array of integers, return the average of all positive elements.
Code Completion
Given an array of integers, return the average of all positive elements.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
341
Given an array of strings and a string s, return the average length of all strings containing s.
Code Completion
Given an array of strings and a string s, return the average length of all strings containing s.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
342
Given an array of integers, return the product of all non-zero elements.
Code Completion
Given an array of integers, return the product of all non-zero elements.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
343
Given an array of integers, give the smallest n so that the sum of the first n elements is at least as large as the sum of the remaining elements.
Code Completion
Given an array of integers, give the smallest n so that the sum of the first n elements is at...
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
344
Given an array of integers, give the largest n ≤ length / 2 so that the sum of the first n elements equals the sum of the last n elements.
Code Completion
Given an array of integers, give the largest n ≤ length / 2 so that the sum of the first...
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
345
Given an array of integers, give the largest sum of n consecutive elements.
Code Completion
Given an array of integers, give the largest sum of n consecutive elements.
CodeCheck
Arrays - Simple Exercises
,
Sums
,
Averages
,
Products
346
Given an array of integers, return an array of length 2 containing the first and last element, in sorted order.
Code Completion
Given an array of integers, return an array of length 2 containing the first and last element, in sorted order.
CodeCheck
Arrays - Simple Exercises
,
Two Answers
347
Given an array of integers, return an array of length 2 containing the minimum and the maximum.
Code Completion
Given an array of integers, return an array of length 2 containing the minimum and the maximum.
CodeCheck
Arrays - Simple Exercises
,
Two Answers
348
Given an array of integers, return an array of length 2, with the number of positive and the number of negative elements in the array.
Code Completion
Given an array of integers, return an array of length 2, with the number of positive and the number of...
CodeCheck
Arrays - Simple Exercises
,
Two Answers
349
Given an array of integers, return an array of length 2, each being an array.
Code Completion
Given an array of integers, return an array of length 2, each being an array. The first one holds the...
CodeCheck
Arrays - Simple Exercises
,
Two Answers
350
Given an array of integers, return an array of length 2, each being an array.
Code Completion
Given an array of integers, return an array of length 2, each being an array. The first one holds the...
CodeCheck
Arrays - Simple Exercises
,
Two Answers
351
Given a two-dimensional array of integers, return the average of the four corner elements.
Code Completion
Given a two-dimensional array of integers, return the average of the four corner elements.
CodeCheck
Two-Dimensional Arrays
,
No Loops
352
Given a two-dimensional array of integers, return the middle element if both the row and column lenghts are odd, or the average of the two or four middle elements of one or both is even.
Code Completion
Given a two-dimensional array of integers, return the middle element if both the row and column lenghts are odd, or...
CodeCheck
Two-Dimensional Arrays
,
No Loops
353
Given a two-dimensional array of integers and a string N, E, S, W, give the middle element along the border in the given compass direction, or the average of the two middle ones if the border length is even.
Code Completion
Given a two-dimensional array of integers and a string N, E, S, W, give the middle element along the border...
CodeCheck
Two-Dimensional Arrays
,
No Loops
354
Given a two-dimensional array of integers and a string NW, NW, SW, SE, return the sum of the four elements in the given compass direction.
Code Completion
Given a two-dimensional array of integers and a string NW, NW, SW, SE, return the sum of the four elements...
CodeCheck
Two-Dimensional Arrays
,
No Loops
355
Given a two-dimensional array of integers, row/column indexes r, c, and a string N E S W, return the neighbor in that direction, or 0 if it doesn't exist.
Code Completion
Given a two-dimensional array of integers, row/column indexes r, c, and a string N E S W, return the neighbor...
CodeCheck
Two-Dimensional Arrays
,
No Loops
356
Repeat with NW NE SW SE.
Code Completion
Repeat with NW NE SW SE.
CodeCheck
Two-Dimensional Arrays
,
No Loops
357
Given a two-dimensional array of integers and row/column indexes r, c, return the number of neighbors (not counting the element itself).
Code Completion
Given a two-dimensional array of integers and row/column indexes r, c, return the number of neighbors (not counting the element...
CodeCheck
Two-Dimensional Arrays
,
No Loops
358
On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, positions are marked with a letter between a and h for the column and a number between...
CodeCheck
Two-Dimensional Arrays
,
No Loops
359
Given a list of integers of length ≥ 4, return the average of the first two and last two elements.
Code Completion
Given a list of integers of length ≥ 4, return the average of the first two and last two elements.
CodeCheck
Lists - Simple Exercises
,
No loops
360
Given a list of integers of length ≥ 3, return the average of the first, last, and middle element (or the two middle elements if the length is even).
Code Completion
Given a list of integers of length ≥ 3, return the average of the first, last, and middle element (or...
CodeCheck
Lists - Simple Exercises
,
No loops
361
Given a list of integers, swap the first and last elements.
Code Completion
Given a list of integers, swap the first and last elements.
CodeCheck
Lists - Simple Exercises
,
No loops
362
Given a list of integers, swap the first two and the last two elements.
Code Completion
Given a list of integers, swap the first two and the last two elements.
CodeCheck
Lists - Simple Exercises
,
No loops
363
Given an input string, print the string with the first and last letter removed if they were equal, or the original string if they were not.
Code Completion
Given an input string, print the string with the first and last letter removed if they were equal, or the...
CodeCheck
Branches
,
Branches Without Functions
364
Given an actual time and an alarm clock time, both in “military” format (such as 0730 for 7:30am), print how many more minutes before the alarm rings.
Code Completion
Given an actual time and an alarm clock time, both in “military” format (such as 0730 for 7:30am), print how...
CodeCheck
Branches
,
Branches Without Functions
365
Repeat the preceding exercise for U.
Code Completion
Repeat the preceding exercise for U.S. time (e.g. 7:30am).
CodeCheck
Branches
,
Branches Without Functions
366
Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neigboring lattice point.
Code Completion
Given a point with integer coordinates (x, y) and a compass direction N, E, S, W, print the neigboring lattice...
CodeCheck
Branches
,
Branches Without Functions
367
Repeat with compass directions NW, NE, SW, SE.
Code Completion
Repeat with compass directions NW, NE, SW, SE.
CodeCheck
Branches
,
Branches Without Functions
368
On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, positions are marked with a letter between a and h for the column and a number between...
CodeCheck
Branches
,
Branches Without Functions
369
On a chessboard, fields are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, fields are marked with a letter between a and h for the column and a number between...
CodeCheck
Branches
,
Branches Without Functions
370
Given the x- and y-coordinates of a point, print whether the point lies in the first, second, third, or fourth quadrant plane, or on the x-axis, or on the y-axis, or the origin.
Code Completion
Given the x- and y-coordinates of a point, print whether the point lies in the first, second, third, or fourth...
CodeCheck
Branches
,
Branches Without Functions
371
Given three numbers x, y, z, determine if one of them is the sum of the two others, and then print out the equation.
Code Completion
Given three numbers x, y, z, determine if one of them is the sum of the two others, and then...
CodeCheck
Branches
,
Branches Without Functions
372
Given three numbers x, y, z, print out how whether they are all distinct, two are the same, or all three are the same.
Code Completion
Given three numbers x, y, z, print out how whether they are all distinct, two are the same, or all...
CodeCheck
Branches
,
Branches Without Functions
373
Given two integers x and y, print their sum, but if it is more than 100 or less than 0, print "out of range".
Code Completion
Given two integers x and y, print their sum, but if it is more than 100 or less than 0,...
CodeCheck
Branches
,
Branches Without Functions
374
Given three integers x, y, z, print the sum of the odd integers.
Code Completion
Given three integers x, y, z, print the sum of the odd integers.
CodeCheck
Branches
,
Branches Without Functions
375
Given three input strings, print all but the shortest one.
Code Completion
Given three input strings, print all but the shortest one.
CodeCheck
Branches
,
Branches Without Functions
376
Given a two-dimensional array of integers, return the number of distinct elements.
Code Completion
Given a two-dimensional array of integers, return the number of distinct elements.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
377
Given a two-dimensional array of integers, remove any adjacent duplicate rows by filling the duplicates with zeroes.
Code Completion
Given a two-dimensional array of integers, remove any adjacent duplicate rows by filling the duplicates with zeroes.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
378
Given a two-dimensional array of integers, return the index of the first row that is entirely filled with zeroes.
Code Completion
Given a two-dimensional array of integers, return the index of the first row that is entirely filled with zeroes.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
379
Given a two-dimensional array of integers, return the top left corner of the first subarray of the form <pre>0 0 0 0</pre>
Code Completion
Given a two-dimensional array of integers, return the top left corner of the first subarray of the form
0 0...
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
380
Given a two-dimensional array of integers, return the position of the largest square subarray filled with zeroes, as a list of length 2.
Code Completion
Given a two-dimensional array of integers, return the position of the largest square subarray filled with zeroes, as a list...
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
381
Repeat the previous exercise with subarrays that are not necessarily square.
Code Completion
Repeat the previous exercise with subarrays that are not necessarily square.
CodeCheck
Two-Dimensional Arrays
,
Complex Loops
382
Given a list of integers, count how many elements are negative.
Code Completion
Given a list of integers, count how many elements are negative.
CodeCheck
Lists - Simple Exercises
,
Counting Elements
383
Given a list a, count how many times the ith element from the front equals the ith element from the back.
Code Completion
Given a list a, count how many times the ith element from the front equals the ith element from the...
CodeCheck
Lists - Simple Exercises
,
Counting Elements
384
Given a list of integers and two values a and b, count how many elements are at least a and at most b.
Code Completion
Given a list of integers and two values a and b, count how many elements are at least a and...
CodeCheck
Lists - Simple Exercises
,
Counting Elements
385
Given a list of integers, return the most frequent element.
Code Completion
Given a list of integers, return the most frequent element. If there is more than one element with maximum frequency,...
CodeCheck
Lists - Simple Exercises
,
Counting Elements
386
Given a list of integers, return a list of all elements that occur with maximum frequency.
Code Completion
Given a list of integers, return a list of all elements that occur with maximum frequency.
CodeCheck
Lists - Simple Exercises
,
Counting Elements
387
Given a list of integers, return the position of the first element that occurs more than once, or -1 if all elements occur exactly once.
Code Completion
Given a list of integers, return the position of the first element that occurs more than once, or -1 if...
CodeCheck
Lists - Simple Exercises
,
Counting Elements
388
Given a list of integers, return a list of all elements that occur exactly once.
Code Completion
Given a list of integers, return a list of all elements that occur exactly once.
CodeCheck
Lists - Simple Exercises
,
Counting Elements
389
Given a list of integers, remove all elements that occur more than once, leaving the first occurrence.
Code Completion
Given a list of integers, remove all elements that occur more than once, leaving the first occurrence.
CodeCheck
Lists - Simple Exercises
,
Counting Elements
390
Given two lists of integers a and b of the same length, count the number of positions where the lists have the same elements.
Code Completion
Given two lists of integers a and b of the same length, count the number of positions where the lists...
CodeCheck
Lists - Simple Exercises
,
Counting Elements
391
Given two lists of integers a and b of the same length, count the number of positions where the list elements differ by at least 2.
Code Completion
Given two lists of integers a and b of the same length, count the number of positions where the list...
CodeCheck
Lists - Simple Exercises
,
Counting Elements
392
Given two lists a and b, remove all elements of b from a.
Code Completion
Given two lists a and b, remove all elements of b from a.
CodeCheck
Lists - Simple Exercises
,
Double Loops
393
Given two lists a and b, return a list that contains all elements occurring in a but not in b.
Code Completion
Given two lists a and b, return a list that contains all elements occurring in a but not in b.
CodeCheck
Lists - Simple Exercises
,
Double Loops
394
Given a list a, return the longest n so that the first n elements equal the last n elements.
Code Completion
Given a list a, return the longest n so that the first n elements equal the last n elements.
CodeCheck
Lists - Simple Exercises
,
Double Loops
395
Given a list of integers, return the largest sum of consecutive elements.
Code Completion
Given a list of integers, return the largest sum of consecutive elements.
CodeCheck
Lists - Simple Exercises
,
Double Loops
396
Given a list of integers, return the largest sequence whose reverse also occurs somewhere in the list.
Code Completion
Given a list of integers, return the largest sequence whose reverse also occurs somewhere in the list.
CodeCheck
Lists - Simple Exercises
,
Double Loops
397
Given a list a of integers, return a list of all elements of a that occur exactly once.
Code Completion
Given a list a of integers, return a list of all elements of a that occur exactly once.
CodeCheck
Lists - Simple Exercises
,
Double Loops
398
Given a list of integers, return a list of lists of length 2, containing each unique element together with its frequency.
Code Completion
Given a list of integers, return a list of lists of length 2, containing each unique element together with its...
CodeCheck
Lists - Simple Exercises
,
Double Loops
399
Given a list of integers, return the position of the longest subsequence of consecutive integers a, a + 1, a + 2, .
Code Completion
Given a list of integers, return the position of the longest subsequence of consecutive integers a, a + 1, a...
CodeCheck
Lists - Simple Exercises
,
Double Loops
400
Given an integer n, return a list of length n containing 1 -1 1 -1 .
Code Completion
Given an integer n, return a list of length n containing 1 -1 1 -1 ...
CodeCheck
Lists - Simple Exercises
,
Filling
401
Given integers n and k, return a list of length n containing 0 1 2 .
Code Completion
Given integers n and k, return a list of length n containing 0 1 2 ... k-1 0 1 2...
CodeCheck
Lists - Simple Exercises
,
Filling
402
Given integers a and b, return a list containing a, a + 1, a + 2, .
Code Completion
Given integers a and b, return a list containing a, a + 1, a + 2, ..., b.
CodeCheck
Lists - Simple Exercises
,
Filling
403
Given integers a and b, return a list containing all even numbers that are at least a and at most b.
Code Completion
Given integers a and b, return a list containing all even numbers that are at least a and at most...
CodeCheck
Lists - Simple Exercises
,
Filling
404
Given an integer n, return a list containing 1 2 2 3 3 3 4 4 4 4 .
Code Completion
Given an integer n, return a list containing 1 2 2 3 3 3 4 4 4 4 ... and...
CodeCheck
Lists - Simple Exercises
,
Filling
405
Given a list of integers and a value, return the position of the last occurrence of the value in the list, or -1 if the value does not exist.
Code Completion
Given a list of integers and a value, return the position of the last occurrence of the value in the...
CodeCheck
Lists - Simple Exercises
,
Finding Elements
406
Given a list of integers and a value, return the difference between the last and first position of the value in the list, or -1 if the value does not exist.
Code Completion
Given a list of integers and a value, return the difference between the last and first position of the value...
CodeCheck
Lists - Simple Exercises
,
Finding Elements
407
Given a list of integers and a value, return a list of all positions of the value in the list.
Code Completion
Given a list of integers and a value, return a list of all positions of the value in the list.
CodeCheck
Lists - Simple Exercises
,
Finding Elements
408
Given a list of integers and a value, return the position of the element that is closest to the value.
Code Completion
Given a list of integers and a value, return the position of the element that is closest to the value....
CodeCheck
Lists - Simple Exercises
,
Finding Elements
409
Given two lists of integers of the same length, return the first position where their elements are the same.
Code Completion
Given two lists of integers of the same length, return the first position where their elements are the same.
CodeCheck
Lists - Simple Exercises
,
Finding Elements
410
Given two lists of integers of the same length, return the first position where their elements differ.
Code Completion
Given two lists of integers of the same length, return the first position where their elements differ.
CodeCheck
Lists - Simple Exercises
,
Finding Elements
411
Given two numbers, return true if they both have the same sign.
Code Completion
Given two numbers, return true if they both have the same sign.
CodeCheck
Branches
,
Branches with Functions
412
Write a function that checks whether two points with coordinates x1, y1 and x2, y2 are in the same quadrant.
Code Completion
Write a function that checks whether two points with coordinates x1, y1 and x2, y2 are in the same quadrant.
CodeCheck
Branches
,
Branches with Functions
413
Given two numbers, return their distance if it less than 10, or 10 otherwise.
Code Completion
Given two numbers, return their distance if it less than 10, or 10 otherwise.
CodeCheck
Branches
,
Branches with Functions
414
On a chessboard, positions are marked with a letter between a and h for the column and a number between 1 and 8 for the row.
Code Completion
On a chessboard, positions are marked with a letter between a and h for the column and a number between...
CodeCheck
Branches
,
Branches with Functions
415
Given three numbers x, y, z and a Boolean variable <code>strict</code>, return <code>true</code> if <code>strict</code> is false and x ≤ y ≤ z, or <code>strict</code> is true and x < y < z.
Code Completion
Given three numbers x, y, z and a Boolean variable
strict
, return
true
if
strict
is false and x ≤...
CodeCheck
Branches
,
Branches with Functions
416
Given four numbers a, b, c, d, return true if exactly two of them are the same.
Code Completion
Given four numbers a, b, c, d, return true if exactly two of them are the same.
CodeCheck
Branches
,
Branches with Functions
417
Given three numbers, return true if they are evenly spaced; that is, sorted in ascending or descending order, with the same distance between them.
Code Completion
Given three numbers, return true if they are evenly spaced; that is, sorted in ascending or descending order, with the...
CodeCheck
Branches
,
Branches with Functions
418
Repeat for four numbers.
Code Completion
Repeat for four numbers. Hint: Use the previous problem.
CodeCheck
Branches
,
Branches with Functions
419
Given numbers x, y, and target, return whichever of x and y is closer to the target.
Code Completion
Given numbers x, y, and target, return whichever of x and y is closer to the target. If they have...
CodeCheck
Branches
,
Branches with Functions
420
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N E S W.
Code Completion
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
421
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N E S W NE NW SE SW.
Code Completion
Given a two-dimensional array of integers and row/column positions r, c, return the largest neighbor in the compass directions N...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
422
Given a two-dimensional array of integers and row/column positions r, c, return the compass direction of the largest neighbor as a string N E S W NE NW SE SW.
Code Completion
Given a two-dimensional array of integers and row/column positions r, c, return the compass direction of the largest neighbor as...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
423
Given a two-dimensional array of integers, row/column positions r, c, and a value x, fill the given element and its neighbors in the compass directions N E S W NE NW SE SW with x.
Code Completion
Given a two-dimensional array of integers, row/column positions r, c, and a value x, fill the given element and its...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
424
Given a two-dimensional array a of integers and row/column positions r, c, return a 3x3 array whose middle element is a[r][c], and whose neighbors are copied from the original.
Code Completion
Given a two-dimensional array a of integers and row/column positions r, c, return a 3x3 array whose middle element is...
CodeCheck
Two-Dimensional Arrays
,
Looping over Neighbors
425
Given a two-dimensional array of integers, compute the sum of all positive elements.
Code Completion
Given a two-dimensional array of integers, compute the sum of all positive elements.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
426
Given a two-dimensional array of integers, return the largest element in the array.
Code Completion
Given a two-dimensional array of integers, return the largest element in the array.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
427
Given a two-dimensional array of integers, return the position of the smallest element in the array as a list of length 2.
Code Completion
Given a two-dimensional array of integers, return the position of the smallest element in the array as a list of...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
428
Given a two-dimensional array of integers and a value x, return the position of the first match as a list of length 2.
Code Completion
Given a two-dimensional array of integers and a value x, return the position of the first match as a list...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
429
Given a two-dimensional array of integers and a value x, return the positions of all matching elements, as a list of arrays of length 2.
Code Completion
Given a two-dimensional array of integers and a value x, return the positions of all matching elements, as a list...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
430
Given a two-dimensional array of integers, compute the sum of all elements that are not one of the borders.
Code Completion
Given a two-dimensional array of integers, compute the sum of all elements that are not one of the borders.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
431
Given a two-dimensional square array of integers, compute the sum of all elements that are not on one of the diagonals.
Code Completion
Given a two-dimensional square array of integers, compute the sum of all elements that are not on one of the...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
432
Given a two-dimensional array of integers, replace all negative elements with zero.
Code Completion
Given a two-dimensional array of integers, replace all negative elements with zero.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
433
Given a two-dimensional array of integers, reverse all rows.
Code Completion
Given a two-dimensional array of integers, reverse all rows.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
434
Given a two-dimensional array of integers, shift each row by one to the right and put a 0 at the leftmost column.
Code Completion
Given a two-dimensional array of integers, shift each row by one to the right and put a 0 at the...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
435
Given an r x c array of integers, return an (r + 2) x (c + 2) array whose borders are zero and whose interior is the original array.
Code Completion
Given an r x c array of integers, return an (r + 2) x (c + 2) array whose borders...
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
436
Given a two-dimensional array of integers, return a list of the largest element in each row.
Code Completion
Given a two-dimensional array of integers, return a list of the largest element in each row.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
437
Given a two-dimensional array of integers, return a list of the number of negative elements in each row.
Code Completion
Given a two-dimensional array of integers, return a list of the number of negative elements in each row.
CodeCheck
Two-Dimensional Arrays
,
Looping Over the Entire Array
438
Given a two-dimensional array of integers and a row index, return the largest element in that row.
Code Completion
Given a two-dimensional array of integers and a row index, return the largest element in that row.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
439
Given a two-dimensional array of integers and a row index r, reverse the given row.
Code Completion
Given a two-dimensional array of integers and a row index r, reverse the given row.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
440
Given a two-dimensional square array of integers, reverse both diagonals.
Code Completion
Given a two-dimensional square array of integers, reverse both diagonals.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
441
Given a two-dimensional array of integers and a column index, return the smallest element in that column.
Code Completion
Given a two-dimensional array of integers and a column index, return the smallest element in that column.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
442
Given a two-dimensional array of integers, an index, and a string R or C, return the sum of the elements in that row or column.
Code Completion
Given a two-dimensional array of integers, an index, and a string R or C, return the sum of the elements...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
443
Given a two-dimensional array of integers, a row index r, and a column index c, return the sum of all elements in the given row and column.
Code Completion
Given a two-dimensional array of integers, a row index r, and a column index c, return the sum of all...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
444
Given a two-dimensional array of integers and a string N, E, S, W, return the sum of all elements of the border in the given compass direction.
Code Completion
Given a two-dimensional array of integers and a string N, E, S, W, return the sum of all elements of...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
445
Given a two-dimensional array of integers, return the sum of all elements along the north and south border.
Code Completion
Given a two-dimensional array of integers, return the sum of all elements along the north and south border.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
446
Given a two-dimensional array of integers, return the sum of all elements along all borders but not the corners.
Code Completion
Given a two-dimensional array of integers, return the sum of all elements along all borders but not the corners.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
447
Given a two-dimensional array of integers, return the sum of all elements along all borders including the corners.
Code Completion
Given a two-dimensional array of integers, return the sum of all elements along all borders including the corners.
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
448
Given a two-dimensional square array of integers, return the sum of the elements along both diagonals.
Code Completion
Given a two-dimensional square array of integers, return the sum of the elements along both diagonals. Make sure not to...
CodeCheck
Two-Dimensional Arrays
,
Loops Along a Row or Column
449
Given a list of integers, return the position of the first occurrence of the largest element.
Code Completion
Given a list of integers, return the position of the first occurrence of the largest element.
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
450
Given a list of integers, return the position of the last occurrence of the largest element.
Code Completion
Given a list of integers, return the position of the last occurrence of the largest element.
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
451
Given a list of integers, return the difference of the positions of the first and the last occurrence of the largest element.
Code Completion
Given a list of integers, return the difference of the positions of the first and the last occurrence of the...
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
452
Given a list of integers, return the difference between the maximum and minimum.
Code Completion
Given a list of integers, return the difference between the maximum and minimum.
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
453
Given a list of integers, swap the the maximum and minimum.
Code Completion
Given a list of integers, swap the the maximum and minimum.
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
454
Given a list of integers, return the second-largest element.
Code Completion
Given a list of integers, return the second-largest element.
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
455
Given a list of elements, find the shortest distance between two consecutive elements.
Code Completion
Given a list of elements, find the shortest distance between two consecutive elements.
CodeCheck
Lists - Simple Exercises
,
Maximum and Minimum
456
Given a list of integers and an integer n, remove all elementts > n or < -n.
Code Completion
Given a list of integers and an integer n, remove all elementts > n or < -n. Shift all remaining...
CodeCheck
Lists - Simple Exercises
,
Moving or Removing Elements
457
Given a list of integers, move all zeroes to the back.
Code Completion
Given a list of integers, move all zeroes to the back.
CodeCheck
Lists - Simple Exercises
,
Moving or Removing Elements
458
Given a list of integers, move all zeroes to the front.
Code Completion
Given a list of integers, move all zeroes to the front.
CodeCheck
Lists - Simple Exercises
,
Moving or Removing Elements
459
Given a list of integers, move all negative numbers to the front and all positive numbers to the back, keeping their relative order.
Code Completion
Given a list of integers, move all negative numbers to the front and all positive numbers to the back, keeping...
CodeCheck
Lists - Simple Exercises
,
Moving or Removing Elements
460
Given a list of integers, remove all even elements that occur exactly twice.
Code Completion
Given a list of integers, remove all even elements that occur exactly twice.
CodeCheck
Lists - Simple Exercises
,
Moving or Removing Elements
461
Given a list of integers, remove all adjacent duplicates.
Code Completion
Given a list of integers, remove all adjacent duplicates.
CodeCheck
Lists - Simple Exercises
,
Moving or Removing Elements
462
Given a string s and an integer n, return a string in which each of the characters in s is repeated n times.
Code Completion
Given a string s and an integer n, return a string in which each of the characters in s is...
CodeCheck
Strings
,
Other String Operations
463
Given a string s, return the first vowel that is doubled in the string.
Code Completion
Given a string s, return the first vowel that is doubled in the string.
CodeCheck
Strings
,
Other String Operations
464
Given a string s, return the string with adjacent duplicates removed.
Code Completion
Given a string s, return the string with adjacent duplicates removed. For example, Mississippi yields Misisipi.
CodeCheck
Strings
,
Other String Operations
465
Given a string s and a string t, return a string in which all the characters of s that occur in t have been replaced by a _ character.
Code Completion
Given a string s and a string t, return a string in which all the characters of s that occur...
CodeCheck
Strings
,
Other String Operations
466
Given a string, return a string composed first of all characters at even positions and then of all characters at odd positions.
Code Completion
Given a string, return a string composed first of all characters at even positions and then of all characters at...
CodeCheck
Strings
,
Other String Operations
467
Write a method that undoes the effect of the preceding exercise.
Code Completion
Write a method that undoes the effect of the preceding exercise.
CodeCheck
Strings
,
Other String Operations
468
Given a string and two characters x and y (as strings of length 1), interchange all occurrences of x and y.
Code Completion
Given a string and two characters x and y (as strings of length 1), interchange all occurrences of x and...
CodeCheck
Strings
,
Other String Operations
469
Given a string s and a character c (as string of length 1), return a string with the characters surrounding the first occurrence of c reversed.
Code Completion
Given a string s and a character c (as string of length 1), return a string with the characters surrounding...
CodeCheck
Strings
,
Other String Operations
470
Given a string s and a character c (as string of length 1), return a string with the characters surrounding any occurrence of c reversed.
Code Completion
Given a string s and a character c (as string of length 1), return a string with the characters surrounding...
CodeCheck
Strings
,
Other String Operations
471
Given an integer n, produce the array <pre>0 1 2 3 .
Code Completion
Given an integer n, produce the array
0 1 2 3 ... n 1 2 3 4 ... 0 ......
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
472
Given two two-dimensional arrays a and b of integers with the same number of rows and columns, return a list of the same size where each element is the greater of the corresponding elements in the two arrays.
Code Completion
Given two two-dimensional arrays a and b of integers with the same number of rows and columns, return a list...
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
473
Repeat the preceding exercise where the array dimensions need not match, filling positions that exist in neither array with 0.
Code Completion
Repeat the preceding exercise where the array dimensions need not match, filling positions that exist in neither array with 0.
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
474
Given two two-dimensional arrays of integers with the same number of rows and columns, return the first position where they do not match, as a list of length 2.
Code Completion
Given two two-dimensional arrays of integers with the same number of rows and columns, return the first position where they...
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
475
Given two two-dimensional arrays with the same number of rows, return a list that places them side by side.
Code Completion
Given two two-dimensional arrays with the same number of rows, return a list that places them side by side.
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
476
Repeat where the row lengths don't have to match.
Code Completion
Repeat where the row lengths don't have to match. Fill the shorter array with zeroes.
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
477
Given a two-dimensional array a, return a list whose [i][j] element is the average of the neighbors of a[i][j] in the N, E, S, W direction.
Code Completion
Given a two-dimensional array a, return a list whose [i][j] element is the average of the neighbors of a[i][j] in...
CodeCheck
Two-Dimensional Arrays
,
Producing 2D Arrays
478
Given two strings s and t, return the first position where their characters differ, or -1 if they are identical.
Code Completion
Given two strings s and t, return the first position where their characters differ, or -1 if they are identical.
CodeCheck
Strings
,
Comparing Strings
479
Given two strings s and t, return the first position where their characters are the same, or -1 if there is no such position.
Code Completion
Given two strings s and t, return the first position where their characters are the same, or -1 if there...
CodeCheck
Strings
,
Comparing Strings
480
Given a string s, count how many times the ith character from the front equals the ith character from the back.
Code Completion
Given a string s, count how many times the ith character from the front equals the ith character from the...
CodeCheck
Strings
,
Comparing Strings
481
Given strings s and t, return a list of all positions in which t occurs in s.
Code Completion
Given strings s and t, return a list of all positions in which t occurs in s.
CodeCheck
Strings
,
Finding Substrings
482
Given strings s and t, return a string in which all occurrences of t are removed from s.
Code Completion
Given strings s and t, return a string in which all occurrences of t are removed from s.
CodeCheck
Strings
,
Finding Substrings
483
Given strings s and t, return a string in which all characters in t are removed from s.
Code Completion
Given strings s and t, return a string in which all characters in t are removed from s.
CodeCheck
Strings
,
Finding Substrings
484
Given a string s, return the longest prefix that is repeated somewhere else in the string.
Code Completion
Given a string s, return the longest prefix that is repeated somewhere else in the string.
CodeCheck
Strings
,
Finding Substrings
485
Given a string s, find the longest prefix that also occurs at the end (so that s = p + t + p), and return t, the string without the beginning and the end.
Code Completion
Given a string s, find the longest prefix that also occurs at the end (so that s = p +...
CodeCheck
Strings
,
Finding Substrings
486
Given a string, return the string with the first and last characters swapped.
Code Completion
Given a string, return the string with the first and last characters swapped.
CodeCheck
Strings
,
No Loops
487
Given a string, return the string with the middle two characters removed if it has even length, and the middle character removed if it has odd length.
Code Completion
Given a string, return the string with the middle two characters removed if it has even length, and the middle...
CodeCheck
Strings
,
No Loops
488
Given a string, return the string with the middle two characters swapped if it has even length, and the middle three characters swapped if it has odd length.
Code Completion
Given a string, return the string with the middle two characters swapped if it has even length, and the middle...
CodeCheck
Strings
,
No Loops
489
Given a string, return the string with the first and second half swapped.
Code Completion
Given a string, return the string with the first and second half swapped. If the string has odd length, leave...
CodeCheck
Strings
,
No Loops
490
Given a string, return the string with the first half and the second half doubled.
Code Completion
Given a string, return the string with the first half and the second half doubled. For example, Java becomes JaJavava...
CodeCheck
Strings
,
No Loops
491
Given a string, find the first integer inside and return its value as an integer.
Code Completion
Given a string, find the first integer inside and return its value as an integer. Return 0 if there is...
CodeCheck
Strings
,
Numbers in Strings
492
Given a string, find the sum of all integers inside.
Code Completion
Given a string, find the sum of all integers inside. Return 0 if there is no integer inside.
CodeCheck
Strings
,
Numbers in Strings
493
Given a string, find all integers inside and return a string that separates them by commas.
Code Completion
Given a string, find all integers inside and return a string that separates them by commas.
CodeCheck
Strings
,
Numbers in Strings
494
Given a string in which words are separated by spaces, return the longest word.
Code Completion
Given a string in which words are separated by spaces, return the longest word.
CodeCheck
Strings
,
Words
495
Given a string in which words are separated by spaces, return the first word that is duplicated (such as an accidental “this this”.
Code Completion
Given a string in which words are separated by spaces, return the first word that is duplicated (such as an...
CodeCheck
Strings
,
Words
496
Given a string in which words are separated by spaces, return the first word that is repeated somewhere in the string.
Code Completion
Given a string in which words are separated by spaces, return the first word that is repeated somewhere in the...
CodeCheck
Strings
,
Words
497
Given a string in which words are separated by spaces, and two words a and b, interchange all occurrences of a and b.
Code Completion
Given a string in which words are separated by spaces, and two words a and b, interchange all occurrences of...
CodeCheck
Strings
,
Words
498
Given a list of integers, return the sum of all positive elements.
Code Completion
Given a list of integers, return the sum of all positive elements.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
499
Given a list of integers, find the largest sum of two different elements in the list.
Code Completion
Given a list of integers, find the largest sum of two different elements in the list.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
500
Given a list of floating-point numbers, return a list of the averages of consecutive element pairs of the original list.
Code Completion
Given a list of floating-point numbers, return a list of the averages of consecutive element pairs of the original list.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
501
Given a list of integers and an integer n, return a list of the averages of n consecutive elements of the original list.
Code Completion
Given a list of integers and an integer n, return a list of the averages of n consecutive elements of...
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
502
Given a list of integers, return the average of all elements that are not the maximum or minimum.
Code Completion
Given a list of integers, return the average of all elements that are not the maximum or minimum.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
503
Given a list of integers, replace each element with the average of its neighbors.
Code Completion
Given a list of integers, replace each element with the average of its neighbors.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
504
Given a list of integers, return the sum of all odd elements.
Code Completion
Given a list of integers, return the sum of all odd elements.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
505
Given a list of integers and two values a and b, return the sum of all elements that are at least a and at most b.
Code Completion
Given a list of integers and two values a and b, return the sum of all elements that are at...
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
506
Given a list of integers, return the average of all positive elements.
Code Completion
Given a list of integers, return the average of all positive elements.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
507
Given a list of strings and a string s, return the average length of all strings containing s.
Code Completion
Given a list of strings and a string s, return the average length of all strings containing s.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
508
Given a list of integers, return the product of all non-zero elements.
Code Completion
Given a list of integers, return the product of all non-zero elements.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
509
Given a list of integers, give the largest n so that the sum of the first n elements equals the sum of the remaining elements.
Code Completion
Given a list of integers, give the largest n so that the sum of the first n elements equals the...
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
510
Given a list of integers, give the largest n ≤ length / 2 so that the sum of the first n elements equals the sum of the last n elements.
Code Completion
Given a list of integers, give the largest n ≤ length / 2 so that the sum of the first...
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
511
Given a list of integers, give the largest sum of n consecutive elements.
Code Completion
Given a list of integers, give the largest sum of n consecutive elements.
CodeCheck
Lists - Simple Exercises
,
Sums
,
Averages
,
Products
512
Given a list of integers, return a list of length 2 containing the first and last element, in sorted order.
Code Completion
Given a list of integers, return a list of length 2 containing the first and last element, in sorted order.
CodeCheck
Lists - Simple Exercises
,
Two Answers
513
Given a list of integers, return a list of length 2 containing the minimum and the maximum.
Code Completion
Given a list of integers, return a list of length 2 containing the minimum and the maximum.
CodeCheck
Lists - Simple Exercises
,
Two Answers
514
Given a list of integers, return a list of length 2, with the number of positive and the number of negative elements in the list.
Code Completion
Given a list of integers, return a list of length 2, with the number of positive and the number of...
CodeCheck
Lists - Simple Exercises
,
Two Answers
515
Given a list of integers, return a list of length 2, each being a list.
Code Completion
Given a list of integers, return a list of length 2, each being a list. The first one holds the...
CodeCheck
Lists - Simple Exercises
,
Two Answers
516
Given a list of integers, return a list of length 2, each being a list.
Code Completion
Given a list of integers, return a list of length 2, each being a list. The first one holds the...
CodeCheck
Lists - Simple Exercises
,
Two Answers
×
This is a detailed description.