Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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`)

Geschlossen
#26 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@tanujb03 arbeitet bereits daran.

Seit 10.10.2026.

  • #30 von @tanujb03 — offen
  • #44 von @VatsalRaina01 — gemerged

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
22/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug good first issue

What I did

  1. Fresh checkout of main, JDK 17.
  2. 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
  1. 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.

Vorherrschende Sprache
Python
Sterne
1
Forks
6
Ø Merge
23 Std. 30 Min.
Gemergte PRs (30 T.)
20

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus techcsispit/code-corner

Alle Issues in techcsispit/code-corner

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.