Necklace Split

Asked at GoogleOnsite

Reported by the problem's creator, not verified

A necklace is a circular string s made of the letters D and R. A cut c lies between s[c - 1] and s[c], and cut 0 lies between the last letter and the first. For cuts i < j, the two arcs are s[i:j] and s[j:] + s[:i].

Examples

  1. Example 1

    Input: s = DRDR

    Output: [0,2]

    Explanation: Cuts 0 and 2 give arcs DR and DR; each has one D and one R. No smaller i than 0 exists.

  2. Example 2

    Input: s = DDDRRR

    Output: [-1,-1]

    Explanation: The necklace has three D letters, so no arc can receive exactly half of them. No pair of cuts works.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.