Rotate String

Problem

Given two strings s and goal, return true if and only if s can become goal after some number of shifts on s.

A shift on s consists of moving the leftmost character of s to the rightmost position.

  • For example, if s = “abcde”, then it will be “bcdea” after one shift.

Example 1:

Input: s = "abcde", goal = "cdeab"
Output: true

Example 2:

Input: s = "abcde", goal = "abced"
Output: false

Constraints:

  • 1 <= s.length, goal.length <= 100
  • s and goal consist of lowercase English letters.

Solution

class Solution {
    public boolean rotateString(String s, String goal) {
        return (s + s).contains(goal);
    }
}

Recent posts from blogs that I like

British Impressionists on the beach 2

Paintings by Philip Wilson Steer, Blanche back in Dieppe, Walter Sickert, the Bavarian son of a Danish artist and his British wife, and the Irish artist John Lavery, and more.

via The Eclectic Light Company

You learn more about writing from close reading than from writing advice

+ how David Foster Wallace creates drive in an essay

via Henrik Karlsson

How to find meaning in large tech companies

Why do many people hate working in large tech companies?

The obvious answer is “because organizational dysfunction stops them from doing the things they want to do”. Engineers like to write code and ship things, and if their company’s dysfunction is preventing that, it’ll make them unhappy. Right?

S...

via Sean Goedecke