Programming Articles - Page 2128 of 3363

Non-decreasing Array in Python

Arnab Chakraborty
Updated on 27-Apr-2020 09:12:39

1K+ Views

Suppose we have an array with n integers, our task is to check whether it could become nondecreasing by modifying at most one element. We can define an array is non-decreasing if it satisfies this rule: array[i] 0if arr[i - 1] > arr[i + 1], then arr[i + 1] := arr[i]return trueExample (Python)Let us see the following implementation to get a better understanding − Live Democlass Solution(object):    def checkPossibility(self, nums):       if len(nums) nums[i+1]:             if ans:                return False           ... Read More

Merge Two Binary Trees in C++

Arnab Chakraborty
Updated on 27-Apr-2020 08:59:01

777 Views

Suppose we have two binary trees and consider that when we put one of them to cover the other, some nodes of the two trees are overlapped while the others are overlapping. We have to merge them into a new binary tree. The merge rule is like that if two nodes are overlapping, then sum node values up as the new value of the merged node. Otherwise, the non-empty node will be used as the node of the new tree.So if the trees are −Then the output will be −To solve this, we will follow these steps −The method is ... Read More

Shortest Unsorted Continuous Subarray in Python

Arnab Chakraborty
Updated on 27-Apr-2020 08:55:20

355 Views

Suppose we have an integer array, we need to find one continuous subarray such that, if we only sort that subarray in ascending order, then the whole array will be sorted too. We need to find the shortest such subarray and output its length. So if the array is [2, 6, 4, 8, 10, 9, 15], then the output will be 5. The array will be [6, 4, 8, 10, 9]To solve this, we will follow these steps −res := sort the nums as an arrayans := 0set r as a linked listfor i in range 0 to the length ... Read More

Path Sum III in C++

Arnab Chakraborty
Updated on 04-May-2020 06:33:43

306 Views

Suppose we have given a binary tree in which each node holds an integer key. We have to find the paths that sum to a given value. The path should start from root to leaf. We have to find the path where the sum is same.If the tree is like [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, 5, 1], and sum is 22, then it will be −The paths are [[5, 4, 11, 2], [5, 8, 4, 5]].To solve this, we will follow these steps −Use the dfs function to solve this problem, the dfs is ... Read More

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

165 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

241 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

491 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

472 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

Advertisements