Skip to content

Files

Latest commit

2e108b8 · Jul 20, 2023

History

History
This branch is 4 commits behind igorwojda/kotlin-coding-challenges:main.

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 20, 2023
Feb 7, 2023
Feb 7, 2023

Combine two queues

Instructions

Given two queues implement a function which combines the contents of each queue into third queue. The third queue should contain the content of the two queues. The function should handle queues of different lengths without inserting null into the new one. Take into consideration the fact that both queues may be of different length. IntQueue can only expose add, remove, and peek methods to external clients.

Challenge | Solution

Examples

val queueOne = new Queue()
queueOne.add(1)
queueOne.add(2)

val queueTwo = new Queue()
queueTwo.add('Hi')
queueTwo.add('There')

val queueThree = weave(queueOne, queueTwo)
queueThree.remove() // 1
queueThree.remove() // 'Hi'
queueThree.remove() // 2
queueThree.remove() // 'There'