• Post Reply Bookmark Topic Watch Topic
  • New Topic

how do i approach such type of problems?  RSS feed

 
Cool Coder
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monk was having a great time in the Digital World, and was surprised to see a new game called, "Conversion Game". In this game, two arrays of
N integers
A1,A2...AN and
B1,B2...BN are playing against each other and Array
A wants to convert itself in Array B.

Array A can do two types of operations on itslef:
1 Take two adjacent elements Ai and Ai+1 , increase Ai by 1 and decrease Ai+1 by 1.
2 Take two adjacent elements Ai and Ai+1 , decrease Ai by 1 and increase Ai+1 by 1.

Monk being an awesome coder, wants to know whether Array
A can convert itself into Array
B, by using any number of such operations. You have to print "YES" (without quotes), if Array
A can convert itself into array
B, else print "NO" (without quotes).
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My general approach would be to start with small-sized arrays, say two elements each. With the minimally-sized arrays, you can start experimenting with the rules to see what the effects of applying the rules are. Then, I'd increase the size to 3 elements each and observe how that affects the outcome and the strategy for finding a solution. I'd also try to figure out how to tell when a solution cannot be found. After that, it would an iterative process to come up with more and more scenarios to experiment with. After a while, you might be able to see patterns emerge that you can then generalize. With those generalizations, you can then try to define an algorithm that would apply to any number of elements.

In summary:

1. Start small
2. Experiment with different scenarios
3. Try to discern patterns
4. Use patterns to define generalizations
5. Use generalizations to define an algorithm
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!