Posts

Delete space in pattern find

 import java.util.*; class PatternFind {     public static boolean search(int n, int m, char[][] words, String word) {         for (int i = 0; i < n; i++) {             for (int j = 0; j < m; j++) {                 if (dfs(n, m, words, word, i, j, 0)) return true;             }         }         return false;     }     public static boolean dfs(int n, int m, char[][] words, String word, int i, int j, int k) {         if (k == word.length()) return true;         if (i < 0 || i >= n || j < 0 || j >= m || words[i][j] != word.charAt(k))             return false;         char temp = words[i][j];         words[i][j] = '#';         boolean found = dfs(n, m,...

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...

project.py

Image
  #Making recipt for school #Here we are importing the modules which are required from reportlab . platypus import SimpleDocTemplate , Table , Paragraph , TableStyle from reportlab . lib import colors from reportlab . lib . pagesizes import A4 from reportlab . lib . styles import getSampleStyleSheet #here we are adding the data in the recipt data = [[ 'Name of the student' , 'Roll Number' , 'Age ' , 'class' , 'paid fee' , ' payment date' , 'Balance' ]] #taking input and addind into data while True :           try :               name = input ( 'Enter name of the student: ' )               roll = int ( input ( 'Enter roll number:' ))               age = int ( input ( 'Enter age of the student: ' ))               cla = input ( 'Enter the class of the student:class ' )            ...

oops in python

#encapsulation #protected access modifier class parent :     # constructor     def __init__ ( self ):         self . _a = 9 class child ( parent ):       def __init__ ( self ):     #calling constructor in above         parent . __init__ ( self )           print ( f 'calling 1st one: { self . _a } ' )         self . _a = 7         print ( f 'calling 2nd one: { self . _a } ' )         self . _a = 5         print ( f 'calling 3rd one: { self . _a } ' )             child () # if i use print method it will show object also for example print () print ( child ()) print () #creating object and accessing it ob = parent () ob1 = child () print ( f 'accseing parent class: { ob . _a } ' ) print ( f 'accseing child class: { ob1 . _a } ' ) #it always takes updated value #o/p is: c...