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`)
I maintainer di solito rispondono entro 1 giorno
@tanujb03 ci sta già lavorando.
Dal 10/10/2026.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 22/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 1
- Fork
- 6
- Merge medio
- 21h 9m
- PR unite (30g)
- 18
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di techcsispit/code-corner
-
prime/solution.java doesn't compile: public class PrimeCheck in solution.java, README requires Solution.java with a Solution classForse già presa @tanujb03 l’ha presa 4 giorni fa. Apertabug good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
techcsispit/code-corner#35 ·
I maintainer di solito rispondono entro 1 giorno
-
Failed compilations always report 0.000 secondsForse già presa @Nik-2208 l’ha presa 1 giorno fa. Apertabug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
techcsispit/code-corner#37 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Add test cases to a problemForse già presa @25crns l’ha presa 11 giorni fa. Apertagood first issue tests
techcsispit/code-corner#2 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Solve a problem in a language it doesn't have yetForse già presa @praseedbhat l’ha presa 5 giorni fa. Apertafeature good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 52/100
techcsispit/code-corner#1 · 6 commenti · 4 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di techcsispit/code-corner
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
[Bug]: Importing weave changes the process-wide localeForse già presa @himanshu748 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
UX
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
mediajunkie/piper-morgan-product#2008 · 2 commenti ·