Created
July 13, 2018 12:29
-
-
Save dailybird/f650ca02b424d17a37d159d9c1acb87e to your computer and use it in GitHub Desktop.
Answer of question from https://www.hackerrank.com/challenges/append-and-delete/problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def appendAndDelete(s: String, t: String, k: Int): String = { | |
val sLength = s.length | |
val tLength = t.length | |
val minLength = Math.min(sLength, tLength) | |
var done = false | |
var index = 0 | |
while (done == false && index < minLength) { | |
if (s(index).equals(t(index)) == false) { | |
done = true | |
} else { | |
index += 1 | |
} | |
} | |
val stepCount = (sLength - index) + (tLength - index) | |
println(index) | |
println(stepCount) | |
if (k.equals(stepCount) || | |
((k - stepCount) > 0 && 0.equals((k - stepCount) % 2)) || | |
k >= stepCount + 2 * index) | |
"Yes" else "No" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment