• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
November 11, 2024 |10 Views

SDE Sheet - Rearrange characters

  Share   Like
Description
Discussion

This video is part of the Heap section under GFG SDE Sheet.

Given a string S with repeated characters. The task is to rearrange characters in a string such that no two adjacent characters are the same.
Note: The string has only lowercase English alphabets and it can have multiple solutions. Return any one of them.

Example 1:

Input : str = "geeksforgeeks" Output: 1 Explanation: All the repeated characters of the given string can be rearranged so that no adjacent characters in the string is equal. Any correct rearrangement will show a output of 1.

Do check out:-
Problem: https://www.geeksforgeeks.org/problems/rearrange-characters4649/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
Article Link: https://www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/