Zoho Java Aptiude Coding Questions-
10.07.2024
zoho_04_02_2024
package zoho_04_02_2024;
public class Question_1 {
public static void main(String[] args) {
int arr[] = { -4, -3, -2, -1, 4, 3, 2 };
[Link](zoho(arr));
}
public static int zoho(int[] arr) {
int cur = 0;
int h = cur;
for (int i : arr) {
cur += i;
h = [Link](h, cur);
}
return h;
}
}
/* output-0 */
package zoho_04_02_2024;
public class Question_2 {
public static void main(String[] args) {
int[] nums = { 1, 2, 3, 1, 1, 3 };
[Link](zoho(nums));
}
public static int zoho(int[] nums) {
int ans = 0;
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (nums[i] == nums[j]) {
ans++;
}
}
}
return ans;
}
}
/* output-4 */
package zoho_04_02_2024;
import [Link];
public class Question_3 {
public static void main(String[] args) {
int nums[] = { 1, 2, 1 };
int[] ans = zoho(nums);
[Link]([Link](ans));
}
public static int[] zoho(int[] nums) {
int[] ans = new int[2 * [Link]];
for (int i = 0; i < [Link]; i++) {
ans[i] = ans[i + [Link]] = nums[i];
}
return ans;
}
}
/* output-[1, 2, 1, 1, 2, 1] */
package zoho_04_02_2024;
public class Question_4 {
public static void main(String[] args) {
String strs[] = { "flower", "flow", "flight" };
String ans = zoho(strs);
[Link](ans);
}
public static String zoho(String strs[]) {
if ([Link] == 0) {
return "";
}
String temp = strs[0];
for (int i = 1; i < [Link]; i++) {
while (strs[i].indexOf(temp) != 0) {
temp = [Link](0, [Link]() - 1);
if ([Link]()) {
return "";
}
}
}
return temp;
}
}
/* output-fl */
package zoho_04_02_2024;
import [Link];
public class Question_5 {
public static void main(String[] args) {
int[] nums1 = { 2, 4 };
int[] nums2 = { 1, 2, 3, 4 };
[Link]([Link](zoho(nums1, nums2)));
public static int[] zoho(int[] nums1, int[] nums2) {
int[] ans = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
int temp = -1, j = [Link] - 1;
while (j >= 0 && nums2[j] != nums1[i]) {
if (nums2[j] > nums1[i])
temp = nums2[j];
j--;
}
ans[i] = temp;
}
return ans;
}
}
/* output-[3, -1] */
package zoho_04_02_2024;
import [Link];
public class Question_6 {
public static void main(String[] args) {
int[] nums = { 0, 2, 1, 5, 3, 4 };
[Link]([Link](zoho(nums)));
}
public static int[] zoho(int[] nums) {
int[] ans = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
ans[i] = nums[nums[i]];
}
return ans;
}
}
/* output-[0, 1, 2, 4, 5, 3] */
package zoho_04_02_2024;
public class Question_7 {
public static void main(String[] args) {
int[] arr = { 0, 3, 2, 1 };
[Link](zoho(arr));
}
public static boolean zoho(int[] arr) {
if ([Link] < 3)
return false;
int i = 0;
int r = [Link] - 1;
while (i + 1 < [Link] - 1 && arr[i] < arr[i + 1])
i++;
while (r - 1 > 0 && arr[r] < arr[r - 1])
r--;
return i == r;
}
}
/* output-true */
package zoho_10_02_2024_zoho_03_02_2024;
package zoho_10_02_2024_zoho_03_02_2024;
public class Question_1 {
public static void main(String[] args) {
String str1 = "aA";
String str2 = "aAAbbb";
int ans = zoho(str1, str2);
[Link](ans);
}
public static int zoho(String str1, String str2) {
int num = 0;
for (int i = 0; i < [Link](); i++) {
if ([Link]([Link](i)) != -1) {
num++;
}
}
return num;
}
}
/* output-3 */
package zoho_10_02_2024_zoho_03_02_2024;
public class Question_10 {
public static void main(String[] args) {
String s = "abca";
[Link](zoho(s));
}
public static boolean zoho(String s) {
int i = 0;
int j = [Link]() - 1;
while (i <= j) {
if ([Link](i) == [Link](j)) {
i++;
j--;
} else
return help(s, i + 1, j) || help(s, i, j - 1);
}
return true;
}
public static boolean help(String s, int i, int j) {
while (i <= j) {
if ([Link](i) == [Link](j)) {
i++;
j--;
} else
return false;
}
return true;
}
}
/* output-true */
package zoho_10_02_2024_zoho_03_02_2024;
public class Question_2 {
public static void main(String[] args) {
int arr[] = { 1, 0, 0, 0, 1 };
int n = 1;
boolean ans = zoho(arr, n);
[Link](ans);// true
public static boolean zoho(int[] arr, int n) {
int count = 0;
for (int i = 0; i < [Link]; i++) {
if (arr[i] == 0) {
boolean l = (i == 0) || (arr[i - 1] == 0);
boolean r = (i == [Link] - 1) || (arr[i +
1] == 0);
if (l && r) {
arr[i] = 1;
count++;
}
}
}
return count >= n;
}
}
/* output-true */
package zoho_10_02_2024_zoho_03_02_2024;
public class Question_3 {
public static void main(String[] args) {
String strs[] = { "flower", "flow", "flight" };
String ans = zoho(strs);
[Link](ans);
}
public static String zoho(String strs[]) {
if ([Link] == 0) {
return "";
}
String temp = strs[0];
for (int i = 1; i < [Link]; i++) {
while (strs[i].indexOf(temp) != 0) {
temp = [Link](0, [Link]() - 1);
if ([Link]()) {
return "";
}
}
}
return temp;
}
}
/* output-fl */
package zoho_10_02_2024_zoho_03_02_2024;
import [Link];
public class Question_4 {
public static void main(String[] args) {
int n = 5;
int[] ans = zoho(n);
[Link]([Link](ans));
}
public static int[] zoho(int num) {
int[] f = new int[num + 1];
for (int i = 1; i <= num; i++) {
f[i] = f[i >> 1] + (i & 1);
}
return f;
}
}
/* output-[0, 1, 1, 2, 1, 2] */
package zoho_10_02_2024_zoho_03_02_2024;
import [Link];
public class Question_5 {
public static void main(String[] args) {
int nums[] = { 1, 2, 1 };
int[] ans = zoho(nums);
[Link]([Link](ans));
}
public static int[] zoho(int[] nums) {
int[] ans = new int[2 * [Link]];
for (int i = 0; i < [Link]; i++) {
ans[i] = ans[i + [Link]] = nums[i];
}
return ans;
}
}
/* output-[1, 2, 1, 1, 2, 1] */
package zoho_10_02_2024_zoho_03_02_2024;
public class Question_6 {
public static void main(String[] args) {
int[] nums = { 1, 2, 3, 1, 1, 3 };
int ans = zoho(nums);
[Link](ans);
public static int zoho(int[] nums) {
int ans = 0;
for (int i = 0; i < [Link]; i++) {
for (int j = i + 1; j < [Link]; j++) {
if (nums[i] == nums[j]) {
ans++;
}
}
}
return ans;
}
}
/* output-4 */
package zoho_10_02_2024_zoho_03_02_2024;
import [Link];
public class Question_8 {
public static void main(String[] args) {
int[] nums1 = { 2, 4 };
int[] nums2 = { 1, 2, 3, 4 };
[Link]([Link](zoho(nums1, nums2)));
}
public static int[] zoho(int[] nums1, int[] nums2) {
int[] ans = new int[[Link]];
for (int i = 0; i < [Link]; i++) {
int temp = -1, j = [Link] - 1;
while (j >= 0 && nums2[j] != nums1[i]) {
if (nums2[j] > nums1[i])
temp = nums2[j];
j--;
}
ans[i] = temp;
}
return ans;
}
}
/* output-[3, -1] */
package zoho_10_02_2024_zoho_03_02_2024;
public class Question_9 {
public static void main(String[] args) {
int nums[] = { 1, 3, 5, 6 };
int target = 7;
[Link](zoho(nums, target));
}
public static int zoho(int[] A, int target) {
int low = 0;
int high = [Link] - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (A[mid] == target)
return mid;
else if (A[mid] > target)
high = mid - 1;
else
low = mid + 1;
}
return low;
}
}
/* output-4 */