## Interview Question

Country: United States

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

Probably - and it is highly probably - the sequences are simply integers one after another.
So, given start (1) and end(3) the sequences can be :
( You dont have to select all the elements )

1,1,1,1
2,2,
1,1,2,2
1,2,1,2
1,2,2,1
2,1,1,2
1,3
3,1

.... etc.

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

``````package main

import "fmt"

// _GetAllSums variants of summ
func _GetAllSums(A, N int) []map[int]int {
if N == 0 || A == 0 {
return []map[int]int{{}}
}
if A > N {
return _GetAllSums(N, N)
}
if A == 1 {
return []map[int]int{{1: N}}
}
result := _GetAllSums(A-1, N)
t := N - A
countA := 1
for t >= 0 {
tmp := _GetAllSums(A-1, t)
for _, v := range tmp {
v[A] = countA
result = append(result, v)
}
t -= A
countA++
}
return result
}

func Factorial(N int) int64 {
if N < 0 {
N = -N
}
result := int64(1)
for i := N; i > 1; i-- {
result = result * int64(i)
}
return result
}

func CountSums(A, N int) int64 {
r := _GetAllSums(A, N)
result := int64(0)
// Calculate result with permutations with repeating elements
for _, variant := range r {
length := 0
denominator := int64(1)
for _, nums := range variant {
length += nums
denominator *= Factorial(nums)
}
if length > 0 {
result += Factorial(length) / denominator
}
}
return result
}

func main() {
fmt.Println(CountSums(3, 4)) // Output: 7
}``````

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

Don't know how we can get this coded but it could be the sum of all numbers between 1-3 repeating/non-repeating to 4.
1111
112
121
13
22
211
31

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

With python generators

``````def generate_sequence(n):
i = 0
while i < n:
j = i + 1
while j < n:
yield [(i,j), i+j]
j = j + 1
i = i + 1

def get_sequence_sum(n, a):
return (x[0] for x in generate_sequence(n) if  x[1] == a)

print list(get_sequence_sum(10, 7))
print list(get_sequence_sum(12, 10))
print list(get_sequence_sum(8, 9))``````

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

With python generators

``````def generate_sequence(n):
i = 0
while i < n:
j = i + 1
while j < n:
yield [(i,j), i+j]
j = j + 1
i = i + 1

def get_sequence_sum(n, a):
return (x[0] for x in generate_sequence(n) if  x[1] == a)

print list(get_sequence_sum(10, 7))
print list(get_sequence_sum(12, 10))
print list(get_sequence_sum(8, 9))``````

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.