Programming Articles - Page 2146 of 3366

Check If It Is a Straight Line in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:07:21

596 Views

Suppose we have a list of data-points consisting of (x, y) coordinates, we have to check whether the data-points are forming straight line or not. So if the points are like [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7)], then they are forming straight line.To solve this, we will take the differences between each consecutive datapoints, and find the slope. For the first one find the slope. For all other points check whether the slope is same or not. if they are same, then simply return true, otherwise falseExampleLet us see the following implementation to get ... Read More

Split a String in Balanced Strings in C++

Arnab Chakraborty
Updated on 29-Apr-2020 08:05:26

503 Views

As we know that the balanced strings are those which have equal quantity of left and right characters. Suppose we have a balanced string s split it in the maximum amount of balanced strings. We have to return the maximum amount of splitted balanced strings. So if the string is “RLRRLLRLRL”, then output will be 4. as there are four balanced strings. “RL”, “RRLL”, “RL” and “RL” each substring has equal amount of L and R.To solve this, we will follow these steps −initialize cnt := 0, and ans := 0for i := 0 to size of the stringcnt := ... Read More

Unique Number of Occurrences in Python

Akshitha Mote
Updated on 20-Dec-2024 17:35:36

899 Views

Suppose we have an array, and we need to check whether each element has a unique number of occurrences. If no such element exists, we return false; otherwise, we return true. For example, given the array [1, 1, 2, 2, 2, 3, 4, 4, 4, 4], the function will return true because no two elements have the same number of occurrences: 1 occurs twice, 2 occurs three times, 3 occurs once, and 4 occurs four times. Various Techniques to Find Unique Occurrences Following are the various techniques to find the unique occurrence of the elements in a list − ... Read More

How to implement LongFunction using lambda and method reference in Java?

raja
Updated on 14-Jul-2020 08:10:54

323 Views

LongFunction is an in-built functional interface defined in java.util.function package. This functional interface expects a long-valued parameter as input and produces a result. LongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: apply().Syntax@FunctionalInterface public interface LongFunction {  R apply(long value) }Exampleimport java.util.function.LongFunction; public class LongFunctionTest {    public static void main(String[] args) {       LongFunction function1 = (long i) -> { // lambda expression          return i + i;       };       System.out.println("Using Lambda Expression: " + function1.apply(10));       LongFunction ... Read More

XDM – The Download Manager for Linux that ramps up Your Speed to 500%

karthikeya Boyini
Updated on 17-Jan-2020 13:01:06

337 Views

Xtreme download supervisor (xdman) is an effective download supervisor for Linux, which is developed in Java programing language. It can increase download speeds of upto 500% and is an alternative for the windows IDM (Internet Download Manager). It is compatible with many popular internet browsers such as Firefox, Chrome, Opera.Before installing Xtreme Download supervisor, Check if Java is installed or not available by typing java -version in command line.$ java -versionThe sample output should be like this –openjdk version "1.8.0_91" OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)Installing Xtreme Download Manager in LinuxTo put the ... Read More

What are the rules for a functional interface in Java?

raja
Updated on 14-Jul-2020 08:12:26

2K+ Views

A functional interface is a special kind of interface with exactly one abstract method in which lambda expression parameters and return types are matched. It provides target types for lambda expressions and method references.Rules for a functional interfaceA functional interface must have exactly one abstract method.A functional interface has any number of default methods because they are not abstract and implementation already provided by the same.A functional interface declares an abstract method overriding one of the public methods from java.lang.Object still considered as functional interface. The reason is any implementation class to this interface can have implementation for this abstract method either from ... Read More

Selenium WebDriver- Revisiting Important Features

Sharon Christine
Updated on 17-Jan-2020 12:47:23

241 Views

It’s been more than a decade since Selenium automation tool is here to automate our testing needs. As a free to use tool with dedicated community, it has lot of features to make our automation testing more reliable and comfortable. Seeing the growing popularity of Selenium webdriver, let’s revisit some of the important features of it, which proves why Selenium webdriver still stand out in the crowd.Key Features – Selenium WebDriverCompatibility with Many Web BrowsersSelenium WebDriver supports wide range of web browsers available in the market such as Firefox, Chrome, Internet Explorer, Opera, Safari and many more. Unless the other ... Read More

Print all possible combinations of r elements in a given array of size n in C++

sudhir sharma
Updated on 17-Jan-2020 11:42:28

2K+ Views

In this problem, we are given an array of size n and a positive integer r. Our task is to print all possible combinations of the elements of the array of size r.Let’s take an example to understand the problem −Input: {5, 6, 7, 8} ; r = 3 Output : {5, 6, 7}, {5, 6, 8}, {5, 7, 8}, {6, 7, 8}To solve this problem an approach would be fixing elements and then recuring or looping over others to find all combinations. In this, we have to fix first n-r+1 elements only and loop or recur over the rest.Example#include ... Read More

Print all possible expressions that evaluate to a target in C++

sudhir sharma
Updated on 17-Jan-2020 11:38:28

325 Views

In this problem, we are given a string of integers from 0 to 9 and a target value. We have to print out ways in which we can generate expression using +, -, and * operation which is evaluated to the value equal to target.Let’s take an example to understand the topic better −Input: string = “123” , target= 6 Output: { “1+2+3”, “1*2*3” }To solve this problem, we will be creating expressions by placing all possible binary operators between digits and then checking the result of the expression with the target value.We will pass all values to a recursive ... Read More

Print all possible paths from top left to bottom right of a mXn matrix in C++

sudhir sharma
Updated on 17-Jan-2020 11:36:41

387 Views

In this problem, we are given an mXn 2D matrix and we have to print all possible paths from top left to the bottom right of the matrix. For traversal, we can move only right and down in the matrix.Let’s take an example to understand the topic better −Input: 1 3 5 2 8 9 Output: 1 -> 3 -> 5 -> 9 1 -> 3 -> 8 -> 9 1 -> 2 -> 8 -> 9To solve this problem, we will move from one cell to another and print the path on going down and right. We will do ... Read More

Advertisements