Skip to content

Commit

Permalink
Solve smallest element in an odd number array
Browse files Browse the repository at this point in the history
  • Loading branch information
sangaryousmane committed Jun 15, 2023
1 parent 0cd4486 commit 6c6eb53
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Binary file modified out/production/java-interview-questions/Main.class
Binary file not shown.
8 changes: 5 additions & 3 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import intermediate.FindInMountain;
import maharishi.CodingTests;

import java.util.Arrays;

public class Main {
public static void main(String[] args) {

int[] arr = {};
char[] arr = {'a', 'b', 'c'};
int target = 2;
int result = CodingTests.sumOfEvenOdd(arr);
System.out.println(result);
char[] result = CodingTests.startToLength(arr, 1, 3);
System.out.println(Arrays.toString(result));
}


Expand Down
17 changes: 17 additions & 0 deletions src/maharishi/CodingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,21 @@ public static int sumOfEvenOdd(int[] nums){
// odd = X, even = Y so, X - Y
return sumOfOdd - sumOfEven;
}

// Find the set of character arrays that contains length of characters
// starting at the start index (zero-based)
public static char[] startToLength(char[] letters, int start, int length){

if (length < 0 || start < 0 ||
start + length-1 >= letters.length){
return null;
}
char[] sub=new char[length];
int right = start + length; // apply sliding window
for (int i = start; i < right; i++){
sub[i - start] = letters[i];
}

return sub;
}
}

0 comments on commit 6c6eb53

Please sign in to comment.