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
package NearbyWords | |
import kotlin.collections.HashSet | |
fun main(args : Array<String>) { | |
println(nearbyWords("gi")) | |
} | |
fun nearbyWords(word: String): Set<String> { | |
val permutations = getAllWordPermutations(word, 0) |
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
package NearbyWordsAlt | |
import kotlin.collections.HashSet | |
fun main(args : Array<String>) { | |
println(nearbyWords("gi")) | |
} | |
fun getAllWordPermutations(word: String): Set<String> { |
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
package NearbyWords | |
import java.util.LinkedList | |
import kotlin.collections.HashSet | |
typealias CharSet = MutableFifthly<Set<Char>, Iterator<Char>, Char?, Long, Long> | |
class MutableFifthly<A, B, C, D, E>( | |
var first: A, | |
var second: B, |
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
package quicksort | |
import java.util.Collections | |
fun main(args : Array<String>) { | |
val list = "abcdefghijklmnopqrstuvwxyz".toMutableList() | |
Collections.shuffle(list) | |
println("before sort: $list") | |
list.quicksort() |
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
fun main(args : Array<String>) { | |
println("A man, a plan, a canal, Panama!".isContainsPalindrome()) | |
} | |
fun String.isContainsPalindrome(): Boolean { | |
// handel edge cases | |
if(length == 0) | |
return false |
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
fun main(args : Array<String>) { | |
println("abc".generatePermutations()) | |
} | |
fun StringBuilder.generatePermutations(start: Int = 0, finish: Int = length-1, | |
result: MutableSet<String> = HashSet()) : Set<String> { | |
if(start == finish) | |
result.add(String(this)) | |
else | |
for(i in start .. finish) { |
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
import java.io.* | |
import java.math.* | |
import java.text.* | |
import java.util.* | |
import java.util.regex.* | |
val mod = 1000000007 | |
fun maxbit(value: Int): Int = if(value <= 1) value else maxbit(value shr 1) shl 1 |
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
val String.prefixSumOfGenoms: Array<IntArray> | |
get() { | |
val genoms = Array(3) { | |
IntArray(length+1) | |
} | |
for(i in 0 until length) { | |
var (a, c, g) = arrayOf<Short>(0, 0, 0) | |
when(this[i]) { | |
'A' -> {a = 1} |
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
package com.mycompany.myapp.app; | |
import android.app.Application; | |
import android.content.Intent; | |
import com.google.android.gms.common.GooglePlayServicesUtil; | |
import com.google.android.gms.security.ProviderInstaller; | |
import com.google.android.gms.security.ProviderInstaller.ProviderInstallListener; | |
public class MainApplication extends Application { |
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
fun maxDifference(arr: Array<Int>): Int { | |
var min: Pair<Int, Int> = Pair(0, 0) | |
var max: Pair<Int, Int> = Pair(0, 0) | |
var result = -1 | |
for(i in 0 until arr.size) { | |
when { | |
i == 0 -> { | |
min = Pair(i, arr[i]) |
OlderNewer