binary-search/Solution.java: prints -1 when the target is the last element (`9 1 3 5 7 9`) or in a 1-element list (`5 5`)
Mantenedores costumam responder em até 1 dia
@tanujb03 já está trabalhando nisso.
Desde 10/10/2026.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 22/100
Direção de pesquisa
The bug is in problems/binary-search/Solution.java, where the search reports -1 once it narrows to a single position. Check linked pull request #30 first, since work is already under way. Done means 9 1 3 5 7 9 prints 4, 5 5 prints 0, and 3 1 3 prints 1, with those cases added to cases.txt and python3 run.py binary-search passing.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
What I did
- Fresh checkout of
main, JDK 17. - Compile the Java solution and run it on a few inputs (the input is one line: the target, then the sorted list):
cd problems/binary-search
javac Solution.java
echo "9 1 3 5 7 9" | java Solution
echo "5 5" | java Solution
echo "3 1 3" | java Solution
echo "3 1 3 5" | java Solution
- For comparison, the Python solution:
echo "9 1 3 5 7 9" | python3 solution.py
What I expected
The problem README says: "Print the position (starting from 0) of the target in the list, or -1 if it isn't there." (problems/binary-search/README.md)
So 9 1 3 5 7 9 should print 4, 5 5 should print 0, 3 1 3 should print 1, and 3 1 3 5 should print 1.
What happened instead
9 1 3 5 7 9 -> -1 (expected 4)
5 5 -> -1 (expected 0)
3 1 3 -> -1 (expected 1)
3 1 3 5 -> 1 (correct)
The target is found, then reported as missing, whenever the search narrows to a single position. The Python and C++ solutions print the right answer for all of these. python3 run.py binary-search passes today because none of the cases in cases.txt ends the search on a single remaining position.
Environment
code-corner main @ 0c95800, JDK 17, Windows 11.
I'd like to work on the fix for this, and add the failing inputs to cases.txt as the Contributing section asks.
- Linguagem predominante
- Python
- Estrelas
- 1
- Forks
- 6
- Merge médio
- 17h 52min
- PRs com merge (30d)
- 14
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Sem guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de techcsispit/code-corner
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution classTalvez já em andamento @tanujb03 assumiu há 3 dias. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 82/100
techcsispit/code-corner#35 ·
Mantenedores costumam responder em até 1 dia
-
Prime solution in C++ incorrectly returns true for some composite numbersTalvez já em andamento @paramsj assumiu há 2 dias. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 25/100
techcsispit/code-corner#38 ·
Mantenedores costumam responder em até 1 dia
-
Failed compilations always report 0.000 secondsTalvez já em andamento @Shivangi-singh18 assumiu há 2 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 35/100
techcsispit/code-corner#37 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
run.py: Python solutions are skipped on Windows when run via python instead of python3Talvez já em andamento @tanujb03 assumiu há 3 dias. Abertabug good first issue
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 15/100
techcsispit/code-corner#29 ·
Mantenedores costumam responder em até 1 dia
-
fibonacci/solution.c: prints negative numbers for n of 47 or more (F(90) prints -1581614984)Talvez já em andamento @tanujb03 assumiu há 3 dias. Abertabug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 25/100
techcsispit/code-corner#27 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de techcsispit/code-corner
Issues semelhantes
-
python triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
microsoft/semantic-kernel#14590 ·
Mantenedores costumam responder em até 3 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
pinterest/pymemcache#662 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 Meio dia Facilidade para iniciantes 62/100
gnocchixyz/gnocchi#1527 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
tenstorrent/tt-model-manager#181 ·
Mantenedores costumam responder em até 1 dia