Need solution to problem urgently

Revision en1, by simp_pro, 2022-08-22 15:48:26

Source: https://www.geeksforgeeks.org/media-net-interview-experience-for-sde-on-campus/

There is some line missing in the problem statement so I am writing here. Also the code for solution is provided but I am not able to understand

We are given strings containing 1 and 2.

When is string a good ? If we are at index i then we can either move a[i] units left or a[i] units right. We have to start at first index and reach last index such that every index is visited once. If we are able to do the it is a good string

Give 2 strings a, b which are initially good. You can select an array of indexes and for each index i, swap(a[i], b[i]). How many ways are there of selecting an array of indexes such that both strings remain good

Main observation
Code of solution(if you are lazy to open link)
Sample test case

Can someone explain the solution please?

Tags need help, help

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English simp_pro 2022-08-22 15:48:26 2359 Initial revision (published)