Programming Articles - Page 1880 of 3366

Largest Time for Given Digits in C++

Arnab Chakraborty
Updated on 06-Jul-2020 09:15:09

207 Views

Suppose we have an array of 4 digits, we have to find the largest 24-hour time that can be made. We know that the smallest 24-hour time is 00:00, and the largest time is 23:59. Starting from 00:00, a time is larger if more time has elapsed since midnight. We have to return the answer as a string of length 5. If there is no valid time to be returned, then return an empty string.So, if the input is like [1, 2, 3, 4], then the output will be "23:41"To solve this, we will follow these steps −Define a function ... Read More

Delete Columns to Make Sorted in Python

Arnab Chakraborty
Updated on 06-Jul-2020 09:13:15

267 Views

Suppose we have an array of N lowercase letter strings, the array name is A, all strings are of same length. Now, we can choose any set of deletion indices, and for each string, we delete all the characters in those indices.As an example, if we have an array A like ["abcdef", "uvwxyz"] and deletion indices are {0, 2, 3}, then the final array after deletions will be ["bef", "vyz"], and the remaining columns of A are ["b", "v"], ["e", "y"], and ["f", "z"].Suppose we chose a set of deletion indices D like after deletions, each remaining column in A ... Read More

DI String Match in Python

Arnab Chakraborty
Updated on 06-Jul-2020 09:12:21

291 Views

Suppose we have a string S that only contains "I" (to denote increase) or "D" (to denote decrease), let N = size of S. We have to return any permutation A of [0, 1, ..., N] such that for all i in range 0, ..., N-1 −If S[i] is "I", then A[i] < A[i+1]Otherwise when S[i] is "D", then A[i] > A[i+1]So, if the input is like "IDID", then the output will be [0, 4, 1, 3, 2]To solve this, we will follow these steps −A := a list from 0 to N where N is the size of S.res ... Read More

Valid Mountain Array in Python

Arnab Chakraborty
Updated on 06-Jul-2020 09:10:41

959 Views

Suppose we have an array A of integers; we have to check whether it is a valid mountain array or not. We know that A is a mountain array if and only if it satisfies the following situations − size of A >= 3There exists some index i in A such that −A[0] < A[1] < ... A[i-1] < A[i]A[i] > A[i+1] > ... > A[A.length - 1]So, if the input is like [0, 3, 2, 1], then the output will be True.To solve this, we will follow these steps −if size of A < 3, thenreturn Falsei := 1while ... Read More

Reorder Data in Log Files in Python

Arnab Chakraborty
Updated on 06-Jul-2020 09:10:04

437 Views

Suppose we have an array of logs. In that array each entry is a space delimited string of words. The first word in each log is an alphanumeric identifier. Then, there are different types of strings like below −Each word after the id will consist only of lowercase letters;Each word after the id will consist only of digits.We will call these two types of logs as letter-logs and digit-logs respectively. And ti is guaranteed that each log has at least one word after its id.We have to reorder the logs so that all of the letter-logs stays before any digit-log. ... Read More

Java Program for Longest Common Subsequence

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

387 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

2K+ 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

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

Advertisements