Programming Articles - Page 2130 of 3366

Palindrome Linked List in Python

Arnab Chakraborty
Updated on 27-Apr-2020 08:50:56

2K+ Views

Suppose we have a linked list. We have to check whether the list elements are forming a palindrome or not. So if the list element is like [1, 2, 3, 2, 1], then this is a palindrome.To solve this, we will follow these steps −fast := head, slow := head, rev := None and flag := 1if the head is empty, then return truewhile fast and next of fast is availableif next of the next of fast is available, then set flag := 0 and break the loopfast := next of the next of fasttemp := slow, slow := next ... Read More

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

raja
Updated on 15-Jul-2020 04:58:24

145 Views

LongToDoubleFunction is a built-in functional interface and part of java.util.function package. This functional interface accepts a long-valued parameter as input and produces a double-valued result. LongToDoubleFunction can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsDouble().Syntax@FunctionalInterface interface LongToDoubleFunction {  double applyAsDouble(long value); }Example of Lambda Exampleimport java.util.function.LongToDoubleFunction; public class LongToDoubleLambdaTest {    public static void main(String args[]) {       LongToDoubleFunction getDouble = longVal -> { // lambda expression          double doubleVal = longVal;          return doubleVal;       };       long input = ... Read More

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

raja
Updated on 15-Jul-2020 04:59:08

227 Views

LongToIntFunction is a functional interface from java.util.function package introduced in Java 8. This functional interface accepts a long-valued parameter as input and produces an int-valued result. LongToIntFunction interface can be used as an assignment target for a lambda expression or method reference. This interface contains only one abstract method: applyAsInt() and doesn't contain any default and abstract methods.Syntax@FunctionalInterface interface LongToIntFunction {    int applyAsInt(long value); }Example of Lambda Expressionimport java.util.function.LongToIntFunction; public class LongToIntLambdaTest {    public static void main(String args[]) {       LongToIntFunction getInt = longVal -> {     // lambda expression          int intVal = (int)longVal;       ... Read More

Difference between monolithic and microservices architecture

Mahesh Parahar
Updated on 27-Jan-2020 10:37:48

15K+ Views

Monolithic architecture  is built as one large system and is usually one code-base. Monolithic application is tightly coupled and entangled as the application evolves, making it difficult to isolate services for purposes such as independent scaling or code maintainability.It extremely difficult to change technology or language or framework because everything is tightly coupled and depend on each other.Microservices architecture is built as small independent module based on business functionality. In microservices application, each project and services are independent from each other at the code level. Therefore it is easy to  configure and deploy completely and also easy to scale based ... Read More

Difference between ArrayBlockingQueue and ArrayDeque

Mahesh Parahar
Updated on 27-Jan-2020 10:35:13

474 Views

ArrayBlockingQueue stores elements in FIFO order. Insertion of element always happened at the tail of the queue and removal of the element always happened from the head of the queue.  It is thread safe and It is bounded array queue therefore once created, the capacity cannot be changed. It is the implementation of the Blocking queue.As per Java Docs −Resizable-array implementation of the Deque interface. Array deques have no capacity restrictions; they grow as necessary to support usage. They are not thread-safe; in the absence of external synchronization, they do not support concurrent access by multiple threads. Null elements are ... Read More

Difference between OpenId and OAuth

Mahesh Parahar
Updated on 27-Jan-2020 10:29:12

464 Views

OAuth is designed for providing authorization of the third party without providing password. It is http based. OAuth provides an access token that can be exchanged for any supported assertion via an API.OpenId is designed for authentication. In openId third-party authenticate your users for you, by using accounts they already have. It is used to authenticate single sign-on identitySr. No.KeyOAuthOpenId1BasicOAuth is designed for providing authorization of the third party without providing passwordOpenId is designed for authentication.2SessionIt does not initiate user's session.OpenId initiate user's session3Access TokenIt used token concept to provide authorizationIn openId third-party authenticate your users for you, by using ... Read More

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

raja
Updated on 15-Jul-2020 04:56:16

171 Views

IntToLongFunction is a built-in functional interface from java.util.function package. This functional interface accepts an int-valued parameter and produces a long-valued result. IntToLongFunction interface can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsLong().Syntax@FunctionalInterface interface IntToLongFunction {  long applyAsLong(int value); }Example of Lambda Expressionimport java.util.function.IntToLongFunction; public class IntToLongFunctionLambdaTest {    public static void main(String args[]) {       IntToLongFunction getLong = intVal -> {      // lambda expression          long longVal = intVal;          return longVal;       };           int input = 40; ... Read More

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

raja
Updated on 14-Jul-2020 13:58:35

220 Views

IntToDoubleFunction is a functional interface from java.util.function package. This functional interface accepts an int-valued argument and produces a double-valued result. IntToDoubleFunction can be used as an assignment target for a lambda expression or method reference. It contains only one abstract method: applyAsDouble().Syntax@FunctionalInterface interface IntToDoubleFunction {    double applyAsDouble(int value); }Example of Lambda Expressionimport java.util.function.IntToDoubleFunction;; public class IntToDoubleLambdaTest {    public static void main(String[] args) {       IntToDoubleFunction getDouble = intVal -> {      // lambda expression          double doubleVal = intVal;          return doubleVal;       };       int input ... Read More

Print a case where the given sorting algorithm fails in C++

sudhir sharma
Updated on 27-Jan-2020 06:50:32

125 Views

In this problem, we are given a sorting algorithm and a number n. Our task is to print an array of n elements that could not be sorted by the algorithm. i.e the algorithm will fail.Algorithmloop i from 1 to n-1    loop j from i to n-1    if a[j]>a[i+1]       swap(a[i], a[j+1])Let’s look into this sorting algorithm, it is using two nested loops. The outer one will start from 1 to n-1 and inner one from i to n-1, and will check the value of inner loop element and outer loop elements at each iteration and ... Read More

Print a closest string that does not contain adjacent duplicates in C++

sudhir sharma
Updated on 27-Jan-2020 06:47:12

150 Views

In this problem, we are given a string. Our task is to print a string that is closest to the current string and does not contain any adjacent duplicate characters.Let’s take an example to understand the problemInput: string = “good” Output: goadIn this example, we found that the elements at index 1 and 2 are the same, so we change the elements at index 2.To solve this problem, we will traverse the string and check if any two adjacent elements have are same. If yes, then change the second element (if i and i+1 elements are the same, change i+1 ... Read More

Advertisements