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

132
Visualizações
Given a 2-D array containing every possible string of capital letters of length k but one, find the missing string

Given two dimensional k x ((26^k)-1) array, containing every possible string of capital letters of length k, except one of them. How can we know the missing string while reading only theta(26^k) entries of the array, and not theta(k x (26^k)) entries?

We have thought of using 'k' pointers for all the 26^k columns, but it will still be the same as looking k x 26^k entries, we also considered checking for a[:0], a[:1], a[:2], . . . a[:(26^k)-1] but it is still the same as looking for k x 26^k values as slicing also counts as looking at those entries.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's a way to do it in Θ(26^k) time complexity by using an additional O(26^k) space.

Let's look at the intuition first -

  1. Each row of the matrix would have (26^k)-1 entries. In the first row, all letters would have the same frequency except one whose frequency would be one lesser than the other 25. This letter would be the first letter of our missing string.
  2. Now we already know the first letter of our missing string, so for the second row, we don't need to look at all the entries and instead, we can look at only the 26^(k-1) - 1 cols for which the corresponding first-row value was the missing letter.(but now in order to know which cols to look into we would need to store those cols somewhere else using additional space). And we would only have to look into 26^(k-1) - 1 entries in the second row.
  3. For a given row, we can count the frequency of letters in given entries in the O(no. of entries) and constant space(26 letters). Once we know the missing letter in a given row, we can go through the row again and store indices of all the cols for which the letter is the missing letter and store those indices in a separate array using additional space O(26^(k-1-i)) for ith row.
  4. On subsequent rows, we only visit the cols which are maintained in our previous row's array which contains indices of cols for which the letter was the missing letter. e.g. for the 3rd row, we can do away with looking at just 26^(k-2) - 1 entries for indices which we stored in our array when we looked at the 2nd row.

So the total no. of entries we would have to look at in each row(after summing up the geometric series) would be -

sum{(26 - 1), (26^2 - 1), (26^3 - 1) ... (26^k -1)} = (26*(1 - (26^k))/(1-26) - k

which is Θ(26^k) time and space complexity.

about 4 years ago · Juan Pablo Isaza Relatório
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