- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Program to count how many times we can find "pizza" with given string characters in Python

Suppose we have a lowercase string s, we have to find how many "pizza" strings we can make using the characters present in s. We can use the characters in s in any order, but each character can be used once.

So, if the input is like "ihzapezlzzilaop", then the output will be 2.

To solve this, we will follow these steps −

- p_freq := Frequency of 'p' in s
- i_freq := Frequency of 'i' in s
- z_freq := Frequency of 'z' in s
- a_freq := Frequency of 'a' in s
- return minimum of (p_freq, i_freq, z_freq/2 and a_freq)

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, s): p_freq = s.count('p') i_freq = s.count('i') z_freq = s.count('z') a_freq = s.count('a') return min(p_freq, i_freq, z_freq // 2, a_freq) ob = Solution() print(ob.solve("ihzapezlzzilaop"))

## Input

"ihzapezlzzilaop"

## Output

2

- Related Articles
- Program to count number of unique palindromes we can make using string characters in Python
- Program to find how many ways we can climb stairs (maximum steps at most k times) in Python
- Python Program to Determine How Many Times a Given Letter Occurs in a String Recursively
- Program to find how many ways we can climb stairs in Python
- Program to check whether we can make k palindromes from given string characters or not in Python?
- C++ program to count in how many ways we can paint blocks with two conditions
- Program to find maximum how many water bottles we can drink in Python
- Program to count how many ways we can divide the tree into two trees in Python
- Program to count how many ways we can cut the matrix into k pieces in python
- Program to count number of palindromes of size k can be formed from the given string characters in Python
- Program to find how many total amount of rain we can catch in Python
- Program to count how many blocks are covered k times by walking in Python
- Python Program to Count Number of Lowercase Characters in a String
- Java program to count upper and lower case characters in a given string
- C# program to count upper and lower case characters in a given string

Advertisements