## Interview Question for Students

• -1
of 1 vote

Country: India

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````def allPermutations(level: Int, prefix: Int, remaining: Array[Int]): List[Int] = {
if (remaining.isEmpty) return List[Int]()

println("level = " + level + " prefix = " + prefix + " remaining = " + remaining.mkString(","))

var subsets = List[Int]()

for (i <- 0 until remaining.length) {
val current = remaining(i)
val subset = prefix * math.pow(10, level).toInt + current
println("current = " + current + " subset = " + subset)
subsets = subsets.:+(subset)

val split = remaining.slice(0, i) ++ remaining.slice(i+1, remaining.length)
val childRemaining = split
val childLevel = 1 // level // + 1

subsets = subsets ++ allPermutations(childLevel, prefix = subset, childRemaining)
}
return subsets
}

val output = allPermutations(0, prefix = 0, remaining = Array(4, 5, 6, 7))``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````def allPermutations(level: Int, prefix: Int, remaining: Array[Int]): List[Int] = {
if (remaining.isEmpty) return List[Int]()

println("level = " + level + " prefix = " + prefix + " remaining = " + remaining.mkString(","))

var subsets = List[Int]()

for (i <- 0 until remaining.length) {
val current = remaining(i)
val subset = prefix * math.pow(10, level).toInt + current
println("current = " + current + " subset = " + subset)
subsets = subsets.:+(subset)

val split = remaining.slice(0, i) ++ remaining.slice(i+1, remaining.length)
val childRemaining = split
val childLevel = 1 // level // + 1

subsets = subsets ++ allPermutations(childLevel, prefix = subset, childRemaining)
}
return subsets
}

val output = allPermutations(0, prefix = 0, remaining = Array(4, 5, 6, 7))``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````def allPermutations(level: Int, prefix: Int, remaining: Array[Int]): List[Int] = {
if (remaining.isEmpty) return List[Int]()

println("level = " + level + " prefix = " + prefix + " remaining = " + remaining.mkString(","))

var subsets = List[Int]()

for (i <- 0 until remaining.length) {
val current = remaining(i)
val subset = prefix * math.pow(10, level).toInt + current
println("current = " + current + " subset = " + subset)
subsets = subsets.:+(subset)

val split = remaining.slice(0, i) ++ remaining.slice(i+1, remaining.length)
val childRemaining = split
val childLevel = 1 // level // + 1

subsets = subsets ++ allPermutations(childLevel, prefix = subset, childRemaining)
}
return subsets
}

val output = allPermutations(0, prefix = 0, remaining = Array(4, 5, 6, 7))``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````def allPermutations(level: Int, prefix: Int, remaining: Array[Int]): List[Int] = {
if (remaining.isEmpty) return List[Int]()

println("level = " + level + " prefix = " + prefix + " remaining = " + remaining.mkString(","))

var subsets = List[Int]()

for (i <- 0 until remaining.length) {
val current = remaining(i)
val subset = prefix * math.pow(10, level).toInt + current
println("current = " + current + " subset = " + subset)
subsets = subsets.:+(subset)

val split = remaining.slice(0, i) ++ remaining.slice(i+1, remaining.length)
val childRemaining = split
val childLevel = 1 // level // + 1

subsets = subsets ++ allPermutations(childLevel, prefix = subset, childRemaining)
}
return subsets
}

val output = allPermutations(0, prefix = 0, remaining = Array(4, 5, 6, 7))``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.