Java Program for Longest Common Subsequence

AmitDiwan
Updated on 04-Jul-2020 10:55:09

376 Views

Following is the Java program for Longest Common Subsequence −Example Live Demopublic class Demo{    int subseq(char[] a, char[] b, int a_len, int b_len){       int my_arr[][] = new int[a_len + 1][b_len + 1];       for (int i = 0; i

Printing Triangle Pattern in Java

AmitDiwan
Updated on 04-Jul-2020 10:51:38

1K+ Views

Following is the Java program to print Triangle pattern −Example Live Demoimport java.util.*; public class Demo{    public static void main(String[] args){       Scanner my_scan = new Scanner(System.in);       System.out.println("Enter the number of rows which needs to be printed");       int my_row = my_scan.nextInt();       for (int i = 1; i = i; j--){             System.out.print(" ");          }          for (int j = 1; j

Printing Integer Between Strings in Java

AmitDiwan
Updated on 04-Jul-2020 10:49:27

1K+ Views

Following is the Java program to print integer between Strings −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.println("The equals symbol is present between two integer values ");       System.out.println(45+5 + "=" +(56+11));       System.out.println(45+5 + " equals symbol " +(56+11));    } }OutputThe equals symbol is present between two integer values 50=67 50 equals symbol 67A class named Demo contains the main function that prints integer values between two strings.

Rename Multiple Files Using Java

AmitDiwan
Updated on 04-Jul-2020 10:46:58

1K+ Views

Following is the code to rename multiple files using Java −Exampleimport java.io.File; import java.io.IOException; public class Demo{    public static void main(String[] argv) throws IOException{       String path_to_folder = "path\to\folder\where\multiple\files\are\present";       File my_folder = new File(path_to_folder);       File[] array_file = my_folder.listFiles();       for (int i = 0; i < array_file.length; i++){          if (array_file[i].isFile()){             File my_file = new File(path_to_folder + "\" + array_file[i].getName());             String long_file_name = array_file[i].getName();             String[] my_token = long_file_name.split("\s"); ... Read More

Clear Screen Using Java

AmitDiwan
Updated on 04-Jul-2020 10:44:46

3K+ Views

Following is the code to clear screen using Java −Example Live Demopublic class Demo{    public static void main(String[] args){       System.out.print("\033[H\033[2J");       System.out.flush();    } }OutputThe screen would be clearedA class named Demo contains the main function. Here, the ANSI escape code is written, that clears the screen. The flush function resets the cursor to the top of the window screen.

Number of Recent Calls in Python

Arnab Chakraborty
Updated on 04-Jul-2020 10:27:37

438 Views

Suppose we want to write a class called RecentCounter to count recent requests. This class has only one method: ping(t), where t is representing some time in milliseconds. This will return the number of pings that have been made from 3000 milliseconds ago until now. Any ping with time in [t - 3000, t] will count, including the current ping. And it is guaranteed that every call to ping uses a strictly larger value of t than before.So, if the input is like Call ping four times ping(1), ping(100), ping(3001), ping(3002), then the output will be 1, 2, 3, 3 ... Read More

X of a Kind in a Deck of Cards in C++

Arnab Chakraborty
Updated on 04-Jul-2020 10:25:58

301 Views

Suppose we have a deck of cards, each card has an integer written on it. We have to check whether we can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where the following condition satisfies: Each group has exactly X number of cards. All of the cards in each group have the same number.So, if the input is like deck = [1, 2, 3, 4, 4, 3, 2, 1], then the output will be True, as possible partitions are [1, 1], [2, 2], [3, 3], [4, 4].To ... Read More

Smallest Range I in Python

Arnab Chakraborty
Updated on 04-Jul-2020 10:24:36

421 Views

Suppose we have an array A of integers, now for each integer A[i] we can choose any x with range [-K to K] then add x to A[i]. Now after this process, we have some array B. We have to find the smallest possible difference between the maximum value of B and the minimum value of B.So, if the input is like A = [0,10], K = 2, then the output will be 6, as B = [2,8]To solve this, we will follow these steps −MAX := (maximum of A) - KMIN := (minimum of A) + Kdifference := MAX - MINif difference

Groups of Special Equivalent Strings in Python

Arnab Chakraborty
Updated on 04-Jul-2020 10:23:13

304 Views

Suppose we have an array of strings called A. One move onto S consists of swapping any two even indexed characters of S, or any two odd indexed characters of S.Now, two strings S and T are special-equivalent if after any number of moves onto S, S is same as T. So, if S = "zzxy" and T = "xyzz" are special-equivalent because we may make the moves like "zzxy" to "xzzy" to "xyzz" that swap S[0] and S[2], then S[1] and S[3].Now, a group of special-equivalent strings from A is a non-empty subset of A such that −In every ... Read More

Projection Area of 3D Shapes

Arnab Chakraborty
Updated on 04-Jul-2020 10:21:08

513 Views

Suppose there is a N x N grid, we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z. Here each value v = grid[i][j] is showing a tower of v cubes placed on top of grid cell (i, j). We view the projection of these cubes onto the xy, yz, and zx planes. Here, we are viewing the projection when looking at the cubes from the top, the front, and the side view. We have to find the total area of all three projections.So, if the input is like [[1, 2], [3, ... Read More

Advertisements