PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Palo

Find minimum tanks to cover all houses

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's proficiency in algorithm design, specifically greedy strategies and string/array manipulation for coverage and optimization under local adjacency constraints.

  • medium
  • Palo
  • Coding & Algorithms
  • Software Engineer

Find minimum tanks to cover all houses

Company: Palo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a string `S` representing a street: - `'H'` = a house - `'-'` = an empty plot where you may place a water tank A house is considered **covered** (able to collect rainwater) if there is a water tank placed **adjacent** to it (either immediately to its left or right). You may place tanks only on empty plots (`'-'`). Your task is to compute the **minimum number of tanks** needed so that **every house** in `S` is covered. If it is impossible to cover all houses, return `-1`. Example: - Input: `S = "-H-HH--"` - One optimal placement is `"-HTHHT-"` (where `'T'` denotes a tank), which uses `2` tanks. Implement a function that returns the minimum number of tanks required (or `-1` if impossible).

Quick Answer: This question evaluates a candidate's proficiency in algorithm design, specifically greedy strategies and string/array manipulation for coverage and optimization under local adjacency constraints.

Related Interview Questions

  • Find Maximum Rectangle in Bar Chart - Palo (medium)
  • Implement three whiteboard coding tasks - Palo (easy)
Palo logo
Palo
Feb 9, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
0
0

You are given a string S representing a street:

  • 'H' = a house
  • '-' = an empty plot where you may place a water tank

A house is considered covered (able to collect rainwater) if there is a water tank placed adjacent to it (either immediately to its left or right).

You may place tanks only on empty plots ('-'). Your task is to compute the minimum number of tanks needed so that every house in S is covered. If it is impossible to cover all houses, return -1.

Example:

  • Input: S = "-H-HH--"
  • One optimal placement is "-HTHHT-" (where 'T' denotes a tank), which uses 2 tanks.

Implement a function that returns the minimum number of tanks required (or -1 if impossible).

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Palo•More Software Engineer•Palo Software Engineer•Palo Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.