Hacking the Matrix

Report a typo

Neo is trying to hack the Matrix. He has one specific code that might be the key to his success. However, to decipher it, he needs to extract certain characters from this code following special instructions.

Instructions:

  1. Iterate through each character of the code using its index. For this, you can get all indexes .indices;

  2. For each character:

    • If the character's index in the string is even (0-based indexing), extract the first character from the code and use .removeFirst() for this;
    • If the character's index in the string is odd, extract the last character from the code use .removeLast() for this.
  3. Print the series of extracted characters as the result.

Sample Input 1:

1 2 3 8 10 10

Sample Output 1:

1 10 2 10 3 8
Write a program in Kotlin
fun main() {
val list = readln().split(" ").map { it.toInt() }

// write your code here

}
___

Create a free account to access the full topic