Problem · String

Programmer Strings

Learn this problem
MediumMicrosoft logoMicrosoftOA
See Microsoft hiring insights

Problem statement

A programmer string contains letters that can be rearranged to form the word programmer and is a substring of a longer string.

Note that the strings programmer, grammproer, and prozmerqgram are all classified as programmer strings by this definition.

Given a string, determine the number of indices that lie between the rightmost and leftmost programmer strings that it contains.

Function

programmerStrings(s: String) → int

Complete the function programmerStrings in the editor below.

Examples

Example 1

s = "programmerxxxprozmerqgram"return = 3
Example 1 illustration

In this example, indices 0 - 9 form one programmer string and indices 13 - 24 contain another.

There are 3 indices between the programmer strings, so the function will return 3.

More Microsoft problems

drafts saved locally
public int programmerStrings(String s) {
  // write your code here
}
s"programmerxxxprozmerqgram"
expected3
checking account