HardNo. 2753LeetCode Premium
Count Houses in a Circular Street II — LeetCode 2753 Python Solution
- Topics
- General
- Reading time
- 3 min
- Source
- leetcode.com
The problem
You are given an object street of class Street that represents a circular street and a positive integer k which represents a maximum bound for the number of houses in that street (in other words, the number of houses is less than or equal to k). Houses' doors could be open or closed initially (at least one is open).
Example
- Input
- street = [1,1,1,1], k = 10
- Output
- 4
- Explanation
- There are 4 houses, and all their doors are open.
Python solution
# Definition for a street.
# class Street:
# def closeDoor(self):
# pass
# def isDoorOpen(self):
# pass
# def moveRight(self):
# pass
class Solution:
def houseCount(self, street: Optional["Street"], k: int) -> int:
while not street.isDoorOpen():
street.moveRight()
for i in range(1, k + 1):
street.moveRight()
if street.isDoorOpen():
ans = i
street.closeDoor()
return ansComplexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
| 0194 | Transpose File | Medium |
| 0195 | Tenth Line | Easy |
| 0228 | Summary Ranges | Easy |
Frequently asked questions
- How hard is LeetCode 2753. Count Houses in a Circular Street II?
LeetCode 2753. Count Houses in a Circular Street II is rated Hard on LeetCode.
- What topics does LeetCode 2753. Count Houses in a Circular Street II cover?
LeetCode 2753. Count Houses in a Circular Street II is tagged General on LeetCode.
- Is LeetCode 2753. Count Houses in a Circular Street II a premium problem?
Yes. LeetCode 2753. Count Houses in a Circular Street II is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.