HUSTCODE
Start your coding
journey today

HUSTCODE is the best platform to help you sharpen your problem-solving skills for coding interviews and build a strong foundation for your software development career.

Solve your problems in 
In Browser IDEHands-on Learning Experience

Practice as you learn with our built-in IDE. Each lesson is designed to be followed by a coding exercise to apply the concepts and gain immediate feedback.

Get started
1const INF = Number.MAX_SAFE_INTEGER; 
2const N = 1000;
3  
4const dp = Array.from({ length: 1 << N }, () => Array(N).fill(INF));
5  
6function tsp(mask, i) {
7  if (mask === (1 << N) - 1) {
8    return dist[i][0];
9  }
10  if (dp[mask][i] !== INF) {
11    return dp[mask][i];
12  }
13  for (let next = 0; next < N; next++) {
14    if ((mask & (1 << next)) === 0) {
15      const newMask = mask | (1 << next);
16      dp[mask][i] = Math.min(dp[mask][i], dist[i][next] + tsp(newMask, next));
17    }
18  }
19  return dp[mask][i];
20}
21  
22function solveTSP() {
23  return tsp(1, 0);
24}
25  
26console.log(solveTSP())
Made with in HN

At HUSTCODE, our mission is to help you improve yourself and land your dream job. We have a sizable repository of interview resources for many companies. In the past few years, our students have landed jobs at top companies around the world.