1 minute read

Given lowercase alphabet strings s and t of the same length, return whether there’s some anagram of s, say a, and some anagram of t, say b, such that:

  • a[i] ≤ b[i] for all 0 ≤ i < n or
  • b[i] ≤ a[i] for all 0 ≤ i < n.

Constraints

  • 1 ≤ n = m ≤ 100,000 where n and m are the lengths of s and t.

https://binarysearch.com/problems/Lexicographically-Bigger-String

Examples

Example 1

Input

  • s = adc
  • t = bec

Output

  • answer = True

Explanation

We can have a = "acd" and b = "bce" and we have:

  • "a" ≤ "b"
  • "c" ≤ "c"
  • "d" ≤ "e"

Solution

Categories:

Updated:

Leave a comment