Posts

Showing posts from August, 2025

unsolved java

 // Online Java Compiler // Use this editor to write, compile and run your Java code online class Main {     public static void main(String[] args) {        int [] arr={1,2,3,4,5};        //finging max and second max value         int max=Integer.MIN_VALUE;        int second_max=Integer.MIN_VALUE;        int min=arr[0];        int second_min =arr[0];        for(int i=0;i<arr.length;i++){            if(arr[i]>max){                second_max=max;                max=arr[i];            }            else if(arr[i]>second_max && arr[i]<max){                second_max=arr[i];           ...

deep logic probllems

questions: Here’s a list of intermediate-level array logic-building questions that will make you think beyond basic looping and indexing: 1. Rotation & Shifting Rotate an array k times to the left or right without using an extra array. Shift all zeroes to the end of the array while preserving the order of other elements. 2. Frequency & Counting Find the most frequent element in the array without using a map/dictionary. Count the number of pairs whose sum is equal to a given number . 3. Pattern Recognition Check if the array is a rotation of another given array. Determine if the array is a mountain array (strictly increasing then strictly decreasing). 4. Subarrays & Sums Find the maximum sum subarray (Kadane’s Algorithm). Count all subarrays with sum equal to 0 . 5. Rearrangement Challenges Rearrange the array so that positive and negative numbers alternate (order not important). Rearrange the array so that the first half is ascendin...

mistakes in problems

 // Online Java Compiler // Use this editor to write, compile and run your Java code online class Main {     public static void main(String[] args) {         int [] arr={1,2,3,1};         boolean tr=false;         int count=0;         for(int i=0;i<arr.length;i++){             for(int j=arr.length-1;j>0;j--){                 if(arr[i]==arr[j]){                   count++;                   if(count==arr.length){                       tr=true;                   }                 }             }         }         System.out.pri...

solved java

 class Main{     public static void main(String[] args){        int [] arr={1,2,3,4};        for(int i=0;i<arr.length;i++){            for(int j=0;j<arr.length;j++){                if((arr[i]+arr[j])%2==0){                    System.out.println("Even: "+arr[i]+"+"+arr[j]);                }            }        }             } } //finding maximum and minimum: import java.util.*; class SecondMax {     public static void main(String[] args) {         int[] arr = {1, 2, 3, 4, 5}; // You can test with other arrays too         int max = Integer.MIN_VALUE;         int second_max = Integer.MIN_VALUE;         for...