Computing an alteration. Algorithm. FAANG coding interview question

  Рет қаралды 146

CodeSmart

CodeSmart

2 жыл бұрын

Rearrange the numbers of an array A such that the property of A holds
A[0] less than or equal A[1] greater than or equal A[2] less than or equal A[3] ....
O(n) time complexity.

Пікірлер: 4
@mith9501
@mith9501 2 жыл бұрын
public int[] maxMinAlteration(int ar[]) { for (var i = 0; i < ar.length; i++) { if (i == ar.length - 1) break; if (i % 2 == 0) { if (!(ar[i] = ar[i + 1])) swap(ar, i, i + 1); } } return ar; } private void swap(int[] ar, int i, int j) { var temp = ar[i]; ar[i] = ar[j]; ar[j] = temp; }
@codesmart760
@codesmart760 2 жыл бұрын
Thanks for posting the code. I didn’t know KZbin allows posting code in comment section.
@zum4342
@zum4342 2 жыл бұрын
Hello, thanks for the well-explained theory. Would it also be possible to show how to translate the theory into code, preferably Java or Python?
@codesmart760
@codesmart760 2 жыл бұрын
Sure. I will link GitHub in the description, keep an eye on that.
Number of islands.  FAANG coding interview questions
15:27
CodeSmart
Рет қаралды 143
Dutch National Flag Algorithm. Explained with playing cards.
12:11
Fast and Furious: New Zealand 🚗
00:29
How Ridiculous
Рет қаралды 45 МЛН
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 4,8 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 113 МЛН
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 862 М.
Why UK 🇬🇧 is going Bankrupt? : Detailed Economic Case Study
20:37
JPEG is Dying - And that's a bad thing
8:09
2kliksphilip
Рет қаралды 165 М.
Think Fast, Talk Smart: Communication Techniques
58:20
Stanford Graduate School of Business
Рет қаралды 39 МЛН
Stop, Intel’s Already Dead!
13:47
Linus Tech Tips
Рет қаралды 795 М.
Google Coding Interview With A High School Student
57:24
Clément Mihailescu
Рет қаралды 4,1 МЛН
Big O Notation - Full Course
1:56:16
freeCodeCamp.org
Рет қаралды 545 М.
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
Xiaomi SU-7 Max 2024 - Самый быстрый мобильник
32:11
Клубный сервис
Рет қаралды 555 М.
Ускоряем ваш TV🚀
0:44
ARTEM_CHIBA
Рет қаралды 464 М.
КРАХ WINDOWS 19 ИЮЛЯ 2024 | ОБЪЯСНЯЕМ
10:04
Yanlışlıkla Telefonumu Parçaladım!😱
0:18
Safak Novruz
Рет қаралды 2,6 МЛН