Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

Given string **s** consisting of only A’s and B’s. You can transform the given string to another string by toggling any character. Thus many transformations of the given string are possible. The task is to find the Weight of the maximum weight transformation.

The weight of a string is calculated using the below formula.

Weight of string = Weight of total pairs + weight of single characters - Total number of toggles.

1. Two consecutive characters are considered a pair only if they are different.

2. Weight of a single pair (both characters are different) = 4

3. Weight of a single character = 1

2. Weight of a single pair (both characters are different) = 4

3. Weight of a single character = 1

**Example 1:**

**Input:** s = "AA"
**Output:** 3
**Explanation:** Transformations of given
string are "AA", "AB", "BA" and "BB".
Maximum weight transformation is "AB"
or "BA". And weight is "One Pair -
One Toggle" = 4-1 = 3.

**Example 2:**

**Input:** s = "ABB"
**Output:** 5
**Explanation:** Transformations are "ABB",
"ABA", "AAB", "AAA", "BBB", "BBA", "BAB"
and "BAA" Maximum weight is of original
string 4 + 1 (One Pair + 1 character)

**Your Task: **

You don't need to read input or print anything. Complete the function ** getMaxWeight() **which takes string

1 ≤ N ≤ 10

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Maximum weight transformation of a given string

...