Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

72
Visualizações
Print the length of the longest subarray that is balanced javascript

Given an array of positive and negative integers, denoting different types of parentheses. The positive numbers

xi denotes opening parentheses of type xi and negative number −xi denotes closing parentheses of type xi.

Open parentheses must be closed by the same type of parentheses. Open parentheses must be closed in the

correct order, i.e., never close an open pair before its inner pair is closed (if it has an inner pair). Thus,

[1,2,−2,−1]

is balanced, while [1,2,−1,−2]

is not balanced.

You have to find out the length of the longest sub array that is balanced.

Input Format:

First line contains an input N

(1≤N≤2∗105), denoting the number of parentheses. Second line contains N space separated integers. xi

(−105≤xi≤105,xi≠0) denoting the ith

parentheses of the array.

Output Format:

Print the length of the longest subarray that is balanced.

SAMPLE INPUT

5

1 -1 2 3 -2

SAMPLE OUTPUT

2

Explanation

The longest subarray that is balanced is (1,−1). (2,3,−2) is not balanced as (3) is not balanced.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda