Skip to main content

Posts

Greedy approach to Solve Array/Lists Problems having large number of elements.

Greedy   Approach to Solve Array problems Are you tired of using two loops to check individual elements ? If yes, then try this Greedy Approach to solve these kind of problems. For e.g.,   1) We have two arrays as given below: 2) First, sort the arrays in descending order: 3) Now, check the conditions in a single for loop. Check below for full greedy approach (PYTHON CODE SNIPPET) : count,j=0,0             for j in range(N):                 if A[count]>B[j]:                        count+=1             print(count) Comment below if it works!!! Thank You
Recent posts

How to fix/solve Presentation Error

What is ā€œ Presentation Error ā€? As you start participating in coding competitions, you are fully acknowledged with most of the errors which generally occurs during the program. What to do if you’re facing an error that doesn’t usually occurs i.e., a special type of error known as ā€œ Presentation Error ā€. These errors may occurs due to the following factors: 1)   If there is wrong formatting from your side, the answer seems to be correct but the online judge doesn’t identifies it. 2)   If an output results to an integer but you’re   presenting it in the form of string, then it may be a serious issue. For e.g., the program OUTPUT should be 15.76 ASSUME THAT WE HAVE THE FOLLOWING JAVA CODE SNIPPET : . . String ans="15.76"; System.out.println(ans);        //gives a presentation error . . float correct_form=Float.valueOf(ans); System.out.printf("%.2f",...

How to fix/solve Compilation Error in Python

A Quick Overview on Compilation Error A Compilation Error is a special type of error that occurs while using Python as Source Code. The main reason behind this error is that python is an interpreted language. So, the online judge rather than interpreting it compiles the code and hence the error occurs. The best approach to tackle these kind of problems is either use a compilation command or convert the program in single line using the single function containing the whole program For.e.g., Program to convert a character in LowerCase at a specified place. def mains():                    //Driver Function     n,K=input().split()     n=int(n)     K=int(K)     S=input()     print(S[:(K-1)]+chr(ord(S[K-1])+32)+S[(K):]) mains() Input: 4 3 TEAM Output: TEaM Hope this articles ...

ISC Computer Science-2020 Paper 2(Theory) Q7. Solved

Computer Science Paper -(ISC Programs 2020) Write a program in JAVA to to find the date and the month from a given day number for a particular year. For e.g.  Year: 2020 Day: 64 March 4, 2020     ----------------------------------------------------------------------      import java.util.*; public class Q_7 {     public static void main(String args[])     {         Scanner sc=new Scanner(System.in);         System.out.println("Year : ");         int i,f,s;         int year=sc.nextInt();         System.out.println("Day : ");         int d=sc.nextInt();         int a[]={31,28,31,30,31,30,31,31,30,31,30,31};         String b[]={"January","February","March","April","May","June","July","August","September","October","November","December"}; ...

Let's CODE IT...Bubble Sort In Matrix Ascending Order

Let's do this in easiest way..... ISC Practical 2020 **************************** HERE IS THE CODE: *************************** * import java.util.*; public class Bubble_Sort_In_Matrix_Ascending_Order {     public static void main()     {         Scanner sc=new Scanner(System.in);         int n=0,temp,i,j;         System.out.println("Enter the number of Rows");         int r=sc.nextInt();         System.out.println("Enter the number of Columns");         int c=sc.nextInt();         int arr[][]=new int[r][c];         int brr[]=new int[r*c];         System.out.println("Enter the elements of Matrix");         for( i=0;i<r;i++)         {             for( j=0;j<c;j++)         ...

Let's CODE IT...Bubble Sort In Matrix Descending Order

Let's do this in easiest way..... ISC Practical 2020 **************************** HERE IS THE CODE: *************************** * import java.util.*; public class Bubble_Sort_In_Matrix_Descending_Order {     public static void main()     {         Scanner sc=new Scanner(System.in);         int n=0,temp,i,j;         System.out.println("Enter the number of Rows");         int r=sc.nextInt();         System.out.println("Enter the number of Columns");         int c=sc.nextInt();         int arr[][]=new int[r][c];         int brr[]=new int[r*c];         System.out.println("Enter the elements of Matrix");         for( i=0;i<r;i++)         {             for( j=0;j<c;j++)         ...

Let's CODE IT...Boundary elements in a matrix

If your're looking for easy method to print boundary elements,then you are at the right place..... **************************** HERE IS THE CODE: **************************** import java.util.*; class Only_Boundary_Elements {     public static void main()     {         Scanner sc=new Scanner(System.in);         int i,j,Temp,n=0;         System.out.println("Enter  the Number of Rows");         int r=sc.nextInt();         System.out.println("Enter  the Number of Columns");         int c=sc.nextInt();         int arr[][]=new int[r][c];         System.out.println("Enter the Elements of Matrix");         for(i=0;i<r;i++)         {             for(j=0;j<c;j++)             { ...