Công Nghệ

# Contiguous Array (Largest Subarray with Equal Number of 0s and 1s) | Programming Tutorials

LeetCode 30 Day Challenge PlayList –

Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.

In this tutorial, I have explained how to find largest subarray with equal number of 0s and 1s.

Example 1:

Input: {0, 1}
Output: 2

Explanation: {0, 1} is the longest contiguous subarray with equal number of 0 and 1.

Example 2:

Input : {0, 1, 1, 0, 1, 1, 1, 0}
Output: 4

Explanation: We can form multiple subarrays with equal number of 0 and 1.Out of these {0, 1, 1, 0} is a longest contiguous subarray with equal number of 0 and 1.

Example : 3

Input : {1, 0, 1, 1, 1, 0, 0}
Output: 6

Explanation: Similarly, Here we can also form multiple subarrays with equal number of 0 and 1. Out of these {0, 1, 1, 1, 0, 0} is a longest contiguous subarray with equal number of 0 and 1.

This problem is the day 13 challenge of LeetCode 30 day challenge.

Website –
Paypal –

Nguồn: https://vinhtrinh.com.vn

Xem thêm bài viết khác: https://vinhtrinh.com.vn/cong-nghe/

Công Nghệ
Công Nghệ
Công Nghệ