lmkaher.blogg.se

Kotlin for each with index
Kotlin for each with index








kotlin for each with index

We need to do this without using additional space in O(n) runtime. Problem Statementįind the elements which appear twice in an array of integers, where the elements in the array being : 1 ≤ a ≤ n ( n = size of array). My immediate reaction – “That is easy and I am sure you got it !” But just then there was a two second silence from his end and then he said that he couldn’t get it right since some additional constraints were mentioned to him ‘later’. The problem was to find the duplicates in an array of integers.

kotlin for each with index

Using the same way, our program will print out all characters of the string.During a conversation with my colleague, he mentioned to me about a problem that he was asked in his technical interview. For string str, we can get the character of index i like str. One great feature of Kotlin is that we can access any character of a string by using its index. The program will get all index positions IntRange and it will iterate through them one by one. Using its value, we will get one IntRange of all index positions. indices is a val that returns the range of valid character indices for a char sequence. In this tutorial, we will learn four different ways to do it. Actually, there are different ways to iterate through the characters of a string in kotlin. We will iterate through each character of a string and print out its value to the user. The program will take the string as input from the user and print out all characters of it one by one. In this kotlin programming tutorial, we will learn how to print each character of a string in kotlin.










Kotlin for each with index