logo Practice-It logo

stutterK

Language/Type: Java collections Deque
Author: Marty Stepp (on 2013/01/29)

Write a method named stutterK that accepts a Deque of strings and an integer k as a parameter and modifies its contents so that the first k elements in the deque each occur twice consecutively. The relative ordering of the elements should be retained. Do not use any other collections or arrays as auxiliary storage.

For example, if passed the deque [a, b, c, d, e, f, g, h], and a k of 3, your method would change the deque to [a, a, b, b, c, c, d, e, f, g, h]. If you are passed a value of k that is negative or larger than the deque size, throw an IllegalArgumentException. This method should run in O(N) time for a deque of N elements.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.