Iron, Magnet and Wall Codechef November Long challenge 2020 solution with code explanation -
Iron, Magnet and Wall Codechef November Long challenge 2020 solution with code explanation
Let's read problem statement,
Chef loves to play with iron (Fe) and magnets (Ma). He took a row of cells (numbered through ) and placed some objects in some of these cells. You are given a string with length describing them; for each valid , the -th character of is one of the following:
- 'I' if the -th cell contains a piece of iron
- 'M' if the -th cell contains a magnet
- '_' if the -th cell is empty
- ':' if the -th cell contains a conducting sheet
- 'X' if the -th cell is blocked
If there is a magnet in a cell and iron in a cell , the attraction power between these cells is