Solution 2 for Scaler Topics Fortnightly Contest - 2

Learn via video course
FREE
View all courses
DSA Problem Solving for Interviews using Java
DSA Problem Solving for Interviews using Java
by Jitender Punia
1000
4.9
Start Learning
DSA Problem Solving for Interviews using Java
DSA Problem Solving for Interviews using Java
by Jitender Punia
1000
4.9
Start Learning
Topics Covered

This article is part of the Scaler Topics Fortnightly Contest - 2.

Solution Approach

  • Brute Force: Backtracking
  • Optimised: ans = 4 * A * A-1. Notice that the problem is asking about number of hamiltonian path in a N-wheel graph.

C++ Implementation

Java Implementation

Python Implementation