GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add array rotation utility by Bhanubasyan · Pull Request #7586 · TheAlgorithms/Java

Conversation

@Bhanubasyan

@Bhanubasyan Bhanubasyan commented Aug 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Bhanubasyan and others added 30 commits May 13, 2026 15:42
@Bhanubasyan
Add array rotation utility using reversal algorithm
54c214c
@Bhanubasyan
Fix checkstyle issues
cb3fea7
@Bhanubasyan
Fix checkstyle issues
8376bbe
@Bhanubasyan
Fix checkstyle issues
df2db03
@Bhanubasyan
Fix checkstyle issues
d729f7b
@Bhanubasyan
Fix checkstyle issues
e3d8cb1
@Bhanubasyan
Fix checkstyle issues
3fc7f45
@Bhanubasyan
Fix checkstyle issues
8831d24
@Bhanubasyan
Fix checkstyle issues
0940d5e
@Bhanubasyan
Fix checkstyle issues
4adc28c
@Bhanubasyan
Fix checkstyle issues
f28d8fc
@Bhanubasyan
Fix checkstyle issues
d1152ce
@Bhanubasyan
Fix checkstyle issues
52a57dd
@Bhanubasyan
Fix checkstyle issues
f81884d
@Bhanubasyan
Fix checkstyle issues
43731f0
@Bhanubasyan
Fix checkstyle issues
bb2df00
@Bhanubasyan
Fix checkstyle issues
a21bed0
@Bhanubasyan
Fix checkstyle issues
f9e24d0
@Bhanubasyan
Fix checkstyle issues
a18a7c8
@Bhanubasyan
Fix checkstyle issues
6a7d2c7
@Bhanubasyan
Merge branch 'master' into add-array-rotation-utility
d44a3f4
@Bhanubasyan
Merge branch 'master' into add-array-rotation-utility
c0746a5
@Bhanubasyan
Merge branch 'master' into add-array-rotation-utility
d0bca4f
@Bhanubasyan
Add unit tests for ArrayRotation
81d90cf
@Bhanubasyan
Add unit tests for ArrayRotation
af33548
@Bhanubasyan
Add unit tests for array rotation utility
c11d0ca
@Bhanubasyan
Add unit tests for array rotation utility
0289397
@Bhanubasyan
Fix formatting in ArrayRotation tests
1226614
@Bhanubasyan
Fix formatting in ArrayRotation tests
1f4bc30
@Bhanubasyan
Fix formatting in ArrayRotation tests
ba42f82
Bhanubasyan added 3 commits May 17, 2026 20:44
@Bhanubasyan
Fix formatting in ArrayRotation tests
e6393ac
@Bhanubasyan
Fix formatting in ArrayRotation tests
cf56a80
@Bhanubasyan
Update the Implimentation of ArrayRotatioTest and /Implementing_auto…
0afa70b
…_completing_features_using_trie
@Bhanubasyan
Bhanubasyan requested review from DenizAltunkapan, alxkm and yanglbme as code owners August 29, 2026 15:15
@Bhanubasyan
Merge branch 'master' into add-array-rotation-utility
1409a6e
@codecov-commenter

codecov-commenter commented Aug 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.01%. Comparing base (9d9e348) to head (ced68c8).

Files with missing lines Patch % Lines
...n/java/com/thealgorithms/others/ArrayRotation.java 91.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7586      +/-   ##
============================================
+ Coverage     82.00%   82.01%   +0.01%     
- Complexity     8280     8286       +6     
============================================
  Files           840      841       +1     
  Lines         25872    25896      +24     
  Branches       5053     5055       +2     
============================================
+ Hits          21216    21239      +23     
- Misses         3866     3867       +1     
  Partials        790      790              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Bhanubasyan and others added 8 commits August 29, 2026 21:08
@Bhanubasyan
fix bugs
878d450
@Bhanubasyan
fix bugs
375cfde
@Bhanubasyan
fix bugs
54a4d01
@Bhanubasyan
fix bugs
dc13192
@Bhanubasyan
Fix formatting issues
1999ab4
@Bhanubasyan
Remove redundant Trie main method
2d96fa3
@Bhanubasyan
Remove redundant Trie main method
0bcee66
@Bhanubasyan
Merge branch 'master' into add-array-rotation-utility
5f35122
mohithvardhan002
mohithvardhan002 reviewed Oct 5, 2026
View reviewed changes
Comment thread src/main/java/com/thealgorithms/others/Trie.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/com/thealgorithms/others/ArrayRotation.java Outdated
return;
}

k = k % n;

@mohithvardhan002 mohithvardhan002 Oct 5, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen when k is negative? In Java, % keeps the sign of the dividend, so a negative k can result in invalid indices during reverse(). Could we either normalize k to the range [0, n) or explicitly reject negative values, and add a test for this case?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Bhanubasyan Bhanubasyan Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled negative k by normalizing it to the range [0, n) and added a test case covering negative rotation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/com/thealgorithms/others/ArrayRotationTest.java
void shouldRotateArrayLeftByTwoPositions() {
int[] values = {1, 2, 3, 4, 5};

ArrayRotation.rotateLeft(values, 2);

@mohithvardhan002 mohithvardhan002 Oct 5, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add a test for rotateLeft() when k is greater than the array length? The current test only covers this case for right rotation, while left rotation has separate logic.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Bhanubasyan Bhanubasyan Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a separate test for rotateLeft() when k is greater than the array length.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Bhanubasyan and others added 9 commits October 7, 2026 17:46
@Bhanubasyan
Add tests for array rotation edge case
38dfe13
@Bhanubasyan
Add tests for array rotation edge case
8e83dac
@Bhanubasyan
Remove unrelated Trie implementation
c656c88
@Bhanubasyan
Address array rotation review feedback
fca0a2b
@Bhanubasyan
Add tests for array rotation edge cases
f482484
@Bhanubasyan
Add tests for array rotation edge case
506ce3f
@Bhanubasyan
Fix negative right rotation
7bd6420
@Bhanubasyan
Fix negative rotation test expectation
71c4ff0
@Bhanubasyan
Merge branch 'master' into add-array-rotation-utility
ced68c8
@Bhanubasyan

Bhanubasyan commented Oct 7, 2026 via email

Copy link
Copy Markdown
Contributor Author
Hi Mohith, Thank you for the detailed review and suggestions. I agree with all three points: - I’ll remove Trie.java from this PR and keep the PR focused specifically on the array rotation utility. - I’ll handle negative k by normalizing it to the valid range and add a corresponding test case. - I’ll add a test covering rotateLeft() when k is greater than the array length. I’ll make these changes and update the PR accordingly. Thanks again for the review!
…
On Mon, 5 Oct 2026 at 11:10, Mohith Vardhan Beedupalli < ***@***.***> wrote: ***@***.**** commented on this pull request. ------------------------------ In src/main/java/com/thealgorithms/others/Trie.java <#7586 (comment)>: > @@ -0,0 +1,162 @@ +package com.thealgorithms.others; + +import java.util.ArrayList; +import java.util.List; + +public class Trie { Could we remove Trie.java from this PR? This PR is focused on adding the array rotation utility, but the Trie implementation seems unrelated to the main purpose of the change. Keeping it here makes the PR larger and also introduces additional code that doesn't have corresponding tests. I think it would be cleaner to move the Trie changes into a separate PR. ------------------------------ In src/main/java/com/thealgorithms/others/ArrayRotation.java <#7586 (comment)>: > + } + + /** + * Rotates the array to the right by k positions. + * + * @PARAM nums the input array + * @PARAM k number of rotations + */ + public static void rotateRight(int[] nums, int k) { + int n = nums.length; + + if (n == 0) { + return; + } + + k = k % n; What should happen when k is negative? In Java, % keeps the sign of the dividend, so a negative k can result in invalid indices during reverse(). Could we either normalize k to the range [0, n) or explicitly reject negative values, and add a test for this case? ------------------------------ In src/test/java/com/thealgorithms/others/ArrayRotationTest.java <#7586 (comment)>: > +public class ArrayRotationTest { + + @test + void shouldRotateArrayRightByTwoPositions() { + int[] values = {1, 2, 3, 4, 5}; + + ArrayRotation.rotateRight(values, 2); + + assertArrayEquals(new int[] {4, 5, 1, 2, 3}, values); + } + + @test + void shouldRotateArrayLeftByTwoPositions() { + int[] values = {1, 2, 3, 4, 5}; + + ArrayRotation.rotateLeft(values, 2); Could we also add a test for rotateLeft() when k is greater than the array length? The current test only covers this case for right rotation, while left rotation has separate logic. — Reply to this email directly, view it on GitHub <#7586?email_source=notifications&email_token=BCOZJDD7V65UGJ33Q2HTC3D5SMX33A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKNBQHE4TMMRYG432M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#pullrequestreview-5409962877>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/BCOZJDBPFYQJU5GIDXCH4AT5SMX33AVCNFSNUABEKJSXA33TNF2G64TZHM3DGNBXG43DMMB3JFZXG5LFHM2TEOBXGMYTSOJTGSQXMAQ> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/BCOZJDAEYMZ2TPQDDPAXZND5SMX33A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKNBQHE4TMMRYG432M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG> and Android <https://github.com/notifications/mobile/android/BCOZJDEPCOOFIHC4AYKT7P35SMX33A5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKNBQHE4TMMRYG432M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>. Download it today! You are receiving this because you authored the thread.Message ID: <TheAlgorithms/Java/pull/7586/review/5409962877 ***@***.*** com>
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mohithvardhan002
mohithvardhan002 approved these changes Oct 7, 2026
View reviewed changes

@mohithvardhan002 mohithvardhan002 left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Logic is correct, tests cover the edge cases, and the earlier review comment about left rotation with k > n is addressed. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale label Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@DenizAltunkapan DenizAltunkapan Awaiting requested review from DenizAltunkapan DenizAltunkapan is a code owner
@yanglbme yanglbme Awaiting requested review from yanglbme yanglbme is a code owner
@alxkm alxkm Awaiting requested review from alxkm alxkm is a code owner
1 more reviewer
@mohithvardhan002 mohithvardhan002 mohithvardhan002 approved these changes
Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

stale

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Bhanubasyan @codecov-commenter @mohithvardhan002
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.