Pergunta de entrevista da empresa Deltax

Hard Coding Question Heading ; The Puzzle Masters of Puzzleville Problem Statement : A young prodigy Zoey stumbled upon a mysterious challenge left by puzzle master. Arrange the pieces in unique combination that would sum up to a magic number provided by master. No piece can be used more than once. Find the number of unique combos that are possible.

Respostas da entrevista

Sigiloso

21 de ago. de 2024

def a(b, c, d, e, f, g): if c == e: g.append(tuple(sorted(f))) return if c > e or b >= len(d): return a(b + 1, c + d[b], d, e, f + [d[b]], g) a(b + 1, c, d, e, f, g) def h(i, j, k): l = [] a(0, 0, k, j, [], l) m = set(l) return len(m) # Example usage i = 7 j = 8 k = [10, 1, 2, 7, 6, 1, 5] n = h(i, j, k) print(n) # Expected Output: 4

19

Sigiloso

18 de out. de 2024

1. The Puzzle Masters of Puzzleville by using the concept of dp we can easly solve ,basically the problem is asking about to find how many unique combinations of pieces sum up to a magic number K. #include #include using namespace std; int count_combinations(int N, int K, vector& pieces) { vector dp(K + 1, 0); dp[0] = 1; for (int piece : pieces) { for (int i = K; i >= piece; --i) { dp[i] += dp[i - piece]; } } return dp[K]; } int main() { int N, K; cin >> N >> K; vector pieces(N); for (int i = 0; i > pieces[i]; } cout << count_combinations(N, K, pieces) << endl; return 0; }

Sigiloso

3 de out. de 2024

In c++

3