FastPrepLongest Equal-Zero-One Subarray
Problems/Longest Equal-Zero-One Subarray

Longest Equal-Zero-One Subarray

Motive logoMotive● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Several firsthand Motive reports for a full-time onsite interview name the Contiguous Array problem.

Our version is about 99% the same as the reported questions.

Given a binary array nums, return the maximum length of a contiguous subarray containing the same number of 0s and 1s.

Function

longestBalancedSubarray(nums: int[]) → int

Examples

Example 1

nums = [0,1]return = 2

The full array contains one zero and one one.

Example 2

nums = [0,1,0]return = 2

Either length-two prefix is balanced.

Constraints

  • 0 <= nums.length <= 100000.
  • Every value is 0 or 1.

More Motive Onsite Interview questions

  • Group AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Maximum Weighted Sum After Left RotationsONSITE INTERVIEW · Seen Jan 2026
  • Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Dec 2025
  • Target Triplet SumONSITE INTERVIEW · Seen Dec 2025
  • Validate IP AddressONSITE INTERVIEW · Seen Dec 2025
  • Generate Palindromic PermutationsONSITE INTERVIEW · Seen Dec 2025
  • Minimum Swaps to Group Circular OnesONSITE INTERVIEW · Seen Dec 2025
  • Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Dec 2025
  • Search in Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions
  • Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum Sum Desirable SubarrayGroww · PHONE SCREEN
  • Maximum Subarray Sum with Equal EndpointsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Maximum Size Subarray Sum Equals KeBay · PHONE SCREENeBay interview questions
  • Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Detect a Contiguous Subarray with Target SumMeta · PHONE SCREENMeta interview questions
  • Count Subarrays With Target SumAmazon · PHONE SCREEN
  • Count Subarrays with Sum KByteDance · PHONE SCREENByteDance interview questions
  • Subarray Sum Equals KApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
All Motive interview questionsSee Motive hiring insights
Saved
class Solution {
    public int longestBalancedSubarray(int[] nums) {
      // write your code here
    }
}
Checking account…