Lesson 15 of 34

Array Algorithms: Reverse, Search, Sort

10 min 30 XP

java.util.Arrays class-ൽ ഉപകാരപ്രദമായ helpers ഉണ്ട്: Arrays.toString() array ഭംഗിയായി print ചെയ്യുന്നു, Arrays.sort() അത് sort ചെയ്യുന്നു.

Example: edit me and press Run

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

Interviews-ൽ പലപ്പോഴും library സഹായമില്ലാതെ ചെയ്യാൻ പറയും. Array തിരിക്കാൻ രണ്ട് അറ്റത്തുനിന്നും swap ചെയ്ത് നടുവിൽ കൂടിച്ചേരൂ (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.

രണ്ട് values swap ചെയ്യാൻ അതിലൊന്ന് സൂക്ഷിക്കുന്ന temp variable വേണം.

Challenge

+30 XP

n-ഉം n സംഖ്യകളും വായിച്ച് അവ വിപരീത ക്രമത്തിൽ ഒരു വരിയിൽ spaces കൊണ്ട് വേർതിരിച്ച് print ചെയ്യൂ. 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.