Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Maximal Square in Binary Matrix
00:00
5 left

Maximal Square in Binary Matrix

HardPython

Problem

Given a binary matrix of '0's and '1's, find the largest square containing only '1's and return its area.

Asked in the Coding round stage. This is LC 221 Maximal Square (the poster wrote the number in forum code). The expected approach is dynamic programming.

Input and Output

Implement maximal_square(matrix). matrix is a non-empty list of equal-length strings containing only '0' and '1'. Return an integer representing the area of the largest square containing only '1' cells. If no cell contains '1', return 0.

Constraints

  • 1 <= rows, columns <= 300
  • Each row has the same length
  • Each cell is either '0' or '1'
  • The input matrix is non-empty

Function Signature

def maximal_square(matrix):
Interviewer

Your question is Maximal Square in Binary Matrix. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.