Christ College 2024
Java - Default language
My Stats
EXP gained
1360
Level
5 (Champion)
Community stats
Discussions
0
1
Know more
37
Total problems solved
33
Easy
4
Moderate
0
Hard
0
Ninja

Current streak:

0 days

Longest streak:

10 days

Less

More

Discussions
JAVA | Recursive | Iterative
Interview problems

Recursive :

public class Solution {
public static int[] reverseArray(int n, int[] nums) {
return rev(0, n - 1, nums);
}

public static int[] rev(int start, int end, int[] nums) {
if (start > end) {
return nums;
}
int temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
return rev(start + 1, end - 1, nums);
}
}

Iterative :

public class Solution {
public static int[] reverseArray(int n, int []nums) {
int[] arr = new int[n];
for(int i = 0; i< n; i++) {
arr[n-i-1] = nums[i];
}
return arr;
}
}

Biswaranjan Panda
Published On 01-Nov-2023
58 views
0 replies
Java Simple Solution
Interview problems
import java.util.List;
public class Solution {
public static void printNtimes(int n){
if(n <= 0) {
return;
}

System.out.print("Coding Ninjas ");
printNtimes(n - 1);
}
}
Biswaranjan Panda
Published On 31-Oct-2023
72 views
0 replies