Hackerrank Solution: 1D Array – Part 2 using Kotlin

This tutorial will show you Hackerrank 1D Array Part 2 using Kotlin.

Let’s play a game on an array! You’re standing at index 0 of an n-element array named game. From some index i (where 0 <= i < n), you can perform one of the following moves:

Move Backward: If cell i-1 exists and contains a 0, you can walk back to cell i-1.

Move Forward:

If cell i+1 contains a zero, you can walk to cell i+1.

If cell i+leap contains a zero, you can jump to cell i+leap.

If you’re standing in cell n-1 or the value of i+leap >= n, you can walk or jump off the end of the array and win the game.

In other words, you can move from index i to index i+1, i-1, or i+leap as long as the destination index is a cell containing a 0. If the destination index is greater than n-1, you win the game.

Given leap and game, complete the function in the editor below so that it returns true if you can win the game (or false if you cannot).

Continue reading “Hackerrank Solution: 1D Array – Part 2 using Kotlin”

Validate Email Address with Regular Expression using Kotlin

This tutorial will show you how to validate email address with regular expression using Kotlin. In web applications or standalone applications where we need to send emails to intended recipients, it is recommended to check the valid email address before sending email to those particular emails for safety purpose. Here we will use regular expression (regex) to validate email address using Kotlin programming language. We will also see how to create Kotlin project in Eclipse.

Please read here how to create Kotlin project in Eclipse.

Continue reading “Validate Email Address with Regular Expression using Kotlin”

HackerRank Solution: Valid Username Regular Expression using Kotlin

This tutorial will show you how to solve HackerRank Valid Username Checker using Kotlin. In different web applications we define certain rules for choosing the username, such as, it should consists of maximum 30 characters; it should not have any special character; it may contain one or more digits; it must starts with a letter, etc. So here also we have some certain rules for choosing the username and we will check valid username regular expression in Kotlin language.

Please read here how to create Kotlin project in Eclipse.

Continue reading “HackerRank Solution: Valid Username Regular Expression using Kotlin”

HackerRank Solution: Tag Content Extractor using Kotlin

This tutorial will shoe you how to solve HackerRank Tag Content Extractor. In a tag-based language like XML or HTML, contents are enclosed between a start tag and an end tag like <tag>contents</tag>. Note that the corresponding end tag starts with a /.

Given a string of text in a tag-based language, parse this text and retrieve the contents enclosed within sequences of well-organized tags meeting the following criterion:

The name of the start and end tags must be same. The HTML code <h1>Hello World</h2> is not valid, because the text starts with an h1 tag and ends with a non-matching h2 tag.

Tags can be nested, but content between nested tags is considered not valid. For example, in <h1><a>contents</a>invalid</h1>, contents is valid but invalid is not valid.

Continue reading “HackerRank Solution: Tag Content Extractor using Kotlin”

HackerRank Solution: Subarray using Kotlin

This tutorial will show you how to solve HackerRank Subarray using Kotlin.

A subarray of an n-element array is an array composed from a contiguous block of the original array’s elements. For example, if array=[1,2,3], then the subarrays are [1], [2], [3], [1,2], [2,3], and [1,2,3]. Something like [1,3] would not be a subarray as it’s not a contiguous subsection of the original array.

Please go through first how to create Kotlin project in Eclipse

Continue reading “HackerRank Solution: Subarray using Kotlin”

Creating Kotlin Project in Eclipse

In this tutorial I will show you how to create Kotlin project in Eclipse. This example shows you how to create Kotlin gradle project or Kotlin maven project.

Kotlin is statically typed programming language for modern multiplatform applications. Kotlin has 100% compatibility with Java or vice-versa.

Salient Features of Kotlin

Drastically reduces the amount of boilerplate code.

Avoids entire classes of errors such as null pointer exception.

Leverages existing libraries for the JVM, Android and the browser.

Choose any Java IDE or build from the command line.

Continue reading “Creating Kotlin Project in Eclipse”