Lesson 15 of 34

Array Algorithms: Reverse, Search, SortArray Algorithms: Reverse, Search, Sort

10 min 30 XP

java.util.Arrays class-ல் பயனுள்ள methods உள்ளன: Arrays.toString() array-ஐ அழகாக print செய்யும், Arrays.sort() வரிசைப்படுத்தும்.

The java.util.Arrays class has handy helpers: Arrays.toString() prints an array neatly and Arrays.sort() sorts it.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Interview-ல் library இல்லாமல் எழுதச் சொல்வார்கள். Array-ஐ reverse செய்ய: இரண்டு முனைகளிலிருந்தும் swap செய்து நடுவில் சந்திக்கவும் (two pointers).

Interviews often ask you to do it without library help. To reverse an array, swap from both ends and meet in the middle (the two-pointer technique).

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

இரண்டு மதிப்புகளை swap செய்ய ஒரு temp variable தேவை.

Swapping two values needs a temp variable to hold one of them.

Challenge

+30 XP

n மற்றும் n எண்களைப் படித்து, அவற்றைத் தலைகீழ் வரிசையில் space விட்டு ஒரே வரியில் print செய்யுங்கள். Input: 5 1 2 3 4 5 Output: 5 4 3 2 1

Read n and n numbers, then print them in reverse order on one line, separated by spaces. Input: 5 1 2 3 4 5 Output: 5 4 3 2 1

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.