MockQuestions

Python Beginner Level Strings Mock Interview

To help you prepare for your Python Beginner Level Strings interview, here are 10 interview questions and answer examples.

Get More Information About Our Python Beginner Level Strings Interview Questions

Question 1 of 10

Is the sentence a pangram or not?

This interview question tests the developer's skills with Python strings and loops.

You are given a sentence with no white space. The sentence contains only lowercase English letters. You need to check if the sentence is Pangram or not.

Pangram- A pangram is a sentence where every letter of the English alphabet appears at least once.

/*Example*/

given string- 'thequickbrownfoxjumpsoverthelazydog'
expected output- true

given string- 'mynameisjohn'
expected output- false

Solution:

The solution is pretty easy. We will track the occurrence of every alphabet. If there is at least one letter that does not occur in the given sentence, we return False. We will use an array of size 26 with all values equal to False. Then we will iterate over each letter in the given sentence and will put True to the array corresponding to that letter.

In the array,
'a' will have index 0,
'b' will have index 1,
….
'z' will have index 25,
To find the index from the letter, we can subtract 97 from its ASCII value (character code).
'a' has code 97, so will have index 0,
'b' has code 98, so will have index 1,
...
'z' has code 122, so will have index 25,

def isPangram(sentence: str) -> bool:
	allAlphabets = [False] * 26

	for char in sentence:
		ascii_index = ord(char) - ord('a')
		allAlphabets[ascii_index] = True

	for exists in allAlphabets:
		if not exists:
			return False
	return True

Time complexity- O(n)
Space complexity- O(1)

Written by on June 27th, 2021

Next Question

10 Python Beginner Level Strings Interview Questions & Answers

Below is a list of our Python Beginner Level Strings interview questions. Click on any interview question to view our answer advice and answer examples. You may view 5 answer examples before our paywall loads. Afterwards, you'll be asked to upgrade to view the rest of our answers.

  • 1. Is the sentence a pangram or not?

  • 2. Return the string in lowercase.

  • 3. How many jewels are there?

  • 4. Can you get a string from the binary tree?

  • 5. Are the string arrays equivalent?

  • 6. Decipher the string.

  • 7. Remove vowels from the string.

  • 8. Count the matching items.

  • 9. What is the number of consistent words?

  • 10. Make an anagram.