 My solution to a “Daily Coding Problem” that I received in my mail today.

Given an array of numbers and an index `i`, return the index of the nearest larger number of the number at index `i`, where distance is measured in array indices.

For example, given `[4, 1, 3, 5, 6]` and index `0`, you should return `3`.

If two distances to larger numbers are the equal, then return any one of them. If the array at `i` doesn’t have a nearest larger integer, then return null.

Here’s my solution in,

``````oneFortyFour(arr: number[], i: number): number | null {
if(arr == null || arr == undefined) {
return null;
}
if(i >= arr.length) {
return null;
}
let distance: number | null = null;
let noAtIdxI = arr[i];
for(let iter=0;iter < arr.length; iter++) {
if(iter == i) continue;
let valAtIter = arr[iter];
if(valAtIter >= noAtIdxI) {
if(distance  == null) {
distance = Math.abs(iter - i);
}
else if(Math.abs(iter - i) < distance) {
distance = iter - i;
}
}
}
return distance;
}``````

#### Like the blog? Subscribe for updates

As usual, if you find any of my posts useful support me by  buying or even trying one of my apps on the App Store.

https://mydaytodo.com/apps/

Also, if you can leave a review on the App Store or Google Play Store, that would help too. #### 데일리라이브 · September 25, 2020 at 7:21 am

What a stuff of un-ambiguity and preserveness of valuable
know-how concerning unpredicted feelings.

• #### 토토픽 · September 26, 2020 at 5:05 am

• #### Homelighting · October 10, 2020 at 8:36 pm

Good response in return of this matter with genuine arguments and telling everything concerning that.

• #### Steve · October 15, 2020 at 8:20 pm

Heya just wanted to give you a brief heads up and
• 