Wawancara 150 TeratasMudah

Permutasi Dalam String

Panduan terperinci dan implementasi Python untuk masalah 'Permutasi Dalam String'.

Pernyataan Masalah

Mudah

Diberikan dua string s1 dan s2, kembalikan True jika s2 berisi permutasi s1, atau False sebaliknya.

Dengan kata lain, kembalikan True jika salah satu permutasi s1 adalah substring dari s2.

Tulis fungsi checkInclusion(s1: str, s2: str) -> bool.

Kendala
  • 1 <= len(s1), len(s2) <= 10^4
  • s1 and s2 consist of lowercase English letters

Contoh

Example 1
Input
s1 = "ab", s2 = "eidbaooo"
Output
True
Explanation

s2 contains one permutation of s1: "ba" (starting at index 3).

Example 2
Input
s1 = "ab", s2 = "eidboaoo"
Output
False
Explanation

No permutation of "ab" exists as a contiguous substring in s2.

Need a Hint?
Pertimbangkan untuk menggunakan struktur data khusus Jendela Geser seperti kumpulan atau tumpukan.
Edge Cases to Watch
  • Struktur masukan kosong
  • Masukan elemen tunggal
  • Batasan angka yang besar

Siap Memecahkannya?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Buka di Editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Sumber Daya Python yang Direkomendasikan

Perluas pengetahuan Anda dengan tutorial interaktif terkait, lembar contekan, dan perbandingan kode.