PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Salesforce

Maximal Square and Longest Increasing Subsequence

Last updated: Jul 28, 2026

Quick Overview

Implement two independent analyses: the largest all-ones square in a binary matrix and the length of a strictly increasing subsequence. Account for empty inputs, area-versus-side-length semantics, duplicate values, very large sequences, complexity comparisons, reduced auxiliary space, and witness reconstruction.

  • medium
  • Salesforce
  • Coding & Algorithms
  • Software Engineer

Maximal Square and Longest Increasing Subsequence

Company: Salesforce

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Implement `analyze(matrix, nums)` and return `[max_square_area, lis_length]`. ### Part A: Maximal Square `matrix` is a rectangular grid containing only `0` and `1`. Return the area of the largest axis-aligned square containing only `1` values. Return `0` for an empty matrix. ### Part B: Longest Increasing Subsequence `nums` is an integer array. Return the length of its longest strictly increasing subsequence. A subsequence preserves order but need not be contiguous. Return `0` for an empty array. ## Constraints - At most 500 rows and 500 columns in `matrix` - `0 <= len(nums) <= 200,000` - `-10^9 <= nums[i] <= 10^9` ## Example For ```text matrix = [[1,0,1,0,0], [1,0,1,1,1], [1,1,1,1,1], [1,0,0,1,0]] nums = [10,9,2,5,3,7,101,18] ``` return `[4, 4]`. ## Clarifications The square result is area, not side length. Equal values cannot both extend a strictly increasing subsequence. ## Hint For the square, relate a cell to three neighboring subproblems. For the subsequence, maintain the smallest possible tail value for each achievable length. ## Interview Follow-ups - Present brute-force and optimal approaches for both parts. - Reduce maximal-square auxiliary space to one row. - Reconstruct one longest increasing subsequence.

Quick Answer: Implement two independent analyses: the largest all-ones square in a binary matrix and the length of a strictly increasing subsequence. Account for empty inputs, area-versus-side-length semantics, duplicate values, very large sequences, complexity comparisons, reduced auxiliary space, and witness reconstruction.

Related Interview Questions

  • Delete One Character Type to Minimize Unique Segments - Salesforce (medium)
  • Count the Ways to Split a Digit String into Primes - Salesforce (medium)
  • Find a Valid Task Execution Order with Dependencies - Salesforce (medium)
  • Minimum Sum of Weekly Maximum Costs - Salesforce (medium)
|Home/Coding & Algorithms/Salesforce

Maximal Square and Longest Increasing Subsequence

Salesforce logo
Salesforce
Jul 9, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
1
0

Problem

Implement analyze(matrix, nums) and return [max_square_area, lis_length].

Part A: Maximal Square

matrix is a rectangular grid containing only 0 and 1. Return the area of the largest axis-aligned square containing only 1 values. Return 0 for an empty matrix.

Part B: Longest Increasing Subsequence

nums is an integer array. Return the length of its longest strictly increasing subsequence. A subsequence preserves order but need not be contiguous. Return 0 for an empty array.

Constraints

  • At most 500 rows and 500 columns in matrix
  • 0 <= len(nums) <= 200,000
  • -10^9 <= nums[i] <= 10^9

Example

For

matrix = [[1,0,1,0,0],
          [1,0,1,1,1],
          [1,1,1,1,1],
          [1,0,0,1,0]]
nums = [10,9,2,5,3,7,101,18]

return [4, 4].

Clarifications

The square result is area, not side length. Equal values cannot both extend a strictly increasing subsequence.

Hint

For the square, relate a cell to three neighboring subproblems. For the subsequence, maintain the smallest possible tail value for each achievable length.

Interview Follow-ups

  • Present brute-force and optimal approaches for both parts.
  • Reduce maximal-square auxiliary space to one row.
  • Reconstruct one longest increasing subsequence.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 9,000+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.