Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2015 of 3366
491 Views
JShell is an interactive command-line tool introduced in Java 9. It is also called a REPL tool that takes input, evaluates it, and prints output to the user.In the JShell tool, it's possible to list all variables created by using the internal command "/vars". We have different "/vars" commands available in the JShell tool as listed below./vars /vars [ID] /vars [Variable_Name] /vars -start /vars -all/vars: This command allows to us display the list of all active variables of the current session./vars [ID]: This command displays the variable and its value, corresponding to the entered ID. This ID corresponds to the name of ... Read More
297 Views
A module that provides the implementation for the Service interface contains a "provides" statement in the module descriptor file. If the module doesn’t have the "provides" statement in the module descriptor file, the service loader can't load that module.We can create the Service Provider Interface by using below steps:We create a new Module com.tutorialspoint.serviceproviderinterface.In the src/main/java directory, we create "module-info.java" file.Inside our source directory, we create the package com.tutorialspoint.serviceproviderinterface.spi.Finally, we create the interface ServiceProviderInterface that contains a method: printServiceName() to be implemented.In the below, we can define Service Provider Interface.package com.tutorialspoint.serviceproviderinterface.spi; public interface ServiceProviderInterface { void printServiceName(); }Read More
249 Views
Suppose we have an array A of positive integers, now A[i] represents the value of the i-th sightseeing spot, and two sightseeing spots i and j have distance j - i. Now the score of a pair (i < j) of sightseeing spots is follows this formula (A[i] + A[j] + i - j): We have to find the maximum score of a pair of sightseeing spots. So if the input is like [8, 1, 5, 2, 6], then the output will be 11, as i = 0, j = 2, the value of A[0] + A[2] + 0 – ... Read More
254 Views
Suppose we have an array if equations that represent relationships between variables, now each string equations[i] has the length 4 and takes one of two different forms: "a==b" or "a!=b". Here, a and b are lowercase letters, that are representing one-letter variable names. So we have to find true if and only if it is possible to assign integers to variable names so as to satisfy all the given equations.If the input is like: ["a==b", "b==c", "a==c"], then the answer will be true.To solve this, we will follow these steps −Define a method called getParent(), this will take character x ... Read More
284 Views
Suppose we have two integers A and B, we have to return any string S, such that −S has length A + B and contains exactly A number of letter ‘a’ and B number of ‘b’ letters.Substring “aaa” and “bbb” will not be in the string SSo if the given integers are A = 4, B = 1, then the result will be “aabaa”.To solve this, we will follow these steps −Define a string ret, initially this is emptywhile |A – B| >= 2, if A > B, thenret := ret concatenate ‘aa’decrease A by 2if B is non-zero concatenate ... Read More
846 Views
Suppose we have to make a timebased key-value store class called TimeMap, that supports two operations.set(string key, string value, int timestamp): This will store the key and value, along with the given timestamp.get(string key, int timestamp): This will return a value such that set(key, value, timestamp_prev) was called previously, with timestamp_prev
426 Views
Consider a subarray A[i], A[i+1], ..., A[j] of A is said to be turbulent when it meets these conditions −For i A[k+1] when k is odd, and A[k] < A[k+1] when k is even;Otherwise, for i A[k+1] when k is even, and A[k] < A[k+1] when k is odd.So the subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray. Now find the length of a maximum size turbulent subarray of A. So if the input is like [9, 4, 2, 10, 7, 8, 8, 1, 9], output is 5. This ... Read More
314 Views
Suppose we have to find all non-negative integers of length N such that the absolute difference between every two consecutive digits is K. We have to keep in mind that every number in the answer must not have leading zeros except for the number 0 itself. We may return the answer in any order. So if N = 3 and K = 7, then output will be [181, 292, 707, 818, 929], Here we can see 070 is not a valid number, because it has one leading zero.To solve this, we will follow these steps −Create one matrix called dp, ... Read More
489 Views
Suppose there are 8 prison cells in a row, and in each cell there is a prisoner or that is empty. In each day, whether the cell is occupied or vacant changes according to the following rules −If one cell has two adjacent neighbors that are both occupied or both vacant, then the cell becomes occupied.Otherwise, it becomes empty.We will describe the current state of the prison in the following way: cells[i] will be 1 if the i-th cell is occupied, else cells[i] will be 0.So we have the initial state of the prison, then return the state of the ... Read More