Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

K-Pangrams

Medium Acceptance 20.91% Points 30.00

Given a string str and an integer k, determine if it is possible to transform the string into a pangram using at most k operations.

An operation consists of swapping any alphabetic character in the string with another lowercase alphabetic character.

Note: A pangram is a sentence that contains every letter of the English alphabet at least once.

Examples
Example 1

Example 1

Input: str = "the quick brown fox jumps over the lazy dog", k = 0

Output: true

Explanation: the sentence contains all 26 characters and is already a pangram.

Example 2

Example 2

Input: str = "aaaaaaaaaaaaaaaaaaaaaaaaaa", k = 25

Output: true

Explanation: The word contains 26 instances of 'a'. Since only 25 operations are allowed. We can keep 1 instance and change all others to make str a pangram.

Hints
Hint 1
Expected Time Complexity: O(n)
Hint 2
Expected Auxiliary Space: O(1)
Constraints
  • 1<= str.size() <= 10^5
  • 0<= k <= 50
  • str may contain duplicate characters
  • str contains only lowercase alphabets or spaces.
Companies
Oracle Zoho
Topics
String Hashing
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions