Check If the Array Is Beautiful in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:29:51

573 Views

Suppose we have an array nums of unique elements. We have to check whether these conditions satisfy or not:Elements will be in range 1 to n.The array must not be sorted in ascending order.So, if the input is like nums = [2, 6, 1, 5, 3, 4], then the output will be True.To solve this, we will follow these steps −n := size of numstotal := nums[0]is_sorted := Truefor i in range 1 to n - 1, doif nums[i] is same as nums[i - 1], thenreturn Falseif nums[i] < nums[i - 1], thenis_sorted := Falsetotal := total + nums[i]if is_sorted ... Read More

Check If Array Contains Element Equal to Sum of Remaining Elements in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:28:04

367 Views

Suppose we have an array called nums we have to check whether the array contains an element whose value is same as sum of all other elements.So, if the input is like nums = [3, 2, 10, 4, 1], then the output will be True, 10 = (3+2+4+1).To solve this, we will follow these steps −freq := an empty maptotal := 0for i in range 0 to size of nums - 1, dofreq[nums[i]] := freq[nums[i]] + 1total := total + nums[i]if total is even, thenif freq[quotient of (total / 2)] is non-zero, thenreturn Truereturn FalseLet us see the following implementation ... Read More

Check If Array Has Element Equal to Product of Remaining Elements in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:27:06

163 Views

Suppose we have an array called nums we have to check whether the array contains an element whose value is same as product of all other elements.So, if the input is like nums = [3, 2, 24, 4, 1], then the output will be True, 24 = (3*2*4*1).To solve this, we will follow these steps −mul := 1for i in range 0 to size of nums - 1, domul := mul * nums[i]for i in range 0 to size of nums - 1, doif nums[i] is same as (mul / nums[i]), thenreturn Truereturn FalseLet us see the following implementation to ... Read More

Check If Array Can Be Sorted Using Swaps Between Given Indices in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:25:56

190 Views

Suppose we have an array called nums with unique values from range [0, n – 1]. This array is unsorted. We also have another array of pairs where each pair contains indices where the elements of the array can be swapped. We can swap multiple number of times. We have to check whether we can arrange the array in sorted order using these swaps or not.So, if the input is like nums = [6, 1, 7, 3, 0, 5, 4, 2] pairs = [(0, 4), (6, 0), (2, 7)], then the output will be True, as we can swap index ... Read More

Comparison of Virtual Circuit and Datagram Networks

Moumita
Updated on 15-Jan-2021 06:25:23

8K+ Views

Virtual – circuit and datagram networks are categories of packet switching network. In virtual circuits, a virtual path is established between the source and the destination systems through which the data packets are transferred from the source to the destination. In the other hand, in datagram networks, each data packet called datagram contain adequate header information so that they can be individually routed by all intermediate network switching devices to the destination.DifferencesIssueVirtual – Circuit NetworksDatagram NetworksConnectivityVirtual – circuits are connection oriented networks.Datagram networks are connectionless.PathIn these networks, the path between the source and the destination nodes that is followed by ... Read More

Check If Sums of i-th Row and i-th Column Are Same in Matrix in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:22:35

240 Views

Suppose we have a 2D matrix. We have to check whether the sum of i-th row is same as the sum of i-th column or not.So, if the input is like23451064214671567then the output will be True, as the sum of first row and column is (2 + 3 + 4 + 5) = 14 and (2 + 10 + 1 + 1) = 14.To solve this, we will follow these steps −row := row count of matcol := column count of mattotal_row := 0, total_col := 0for i in range 0 to row - 1, dototal_row := 0, total_col := ... Read More

Check If Sum of Divisors of Two Numbers Are Same in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:21:13

306 Views

Suppose we have two numbers p and q. We have to check whether the sum of all divisors of these tow numbers are same or not.So, if the input is like p = 559, q = 703, then the output will be True the divisors of 559 is 1, 13, 43 and 703 is 1, 19, 37. The sum of the divisors are 57.To solve this, we will follow these steps −Define a function divSum() . This will take ntotal := 1i := 2while i * i

Multi-Protocol Label Switching (MPLS)

Moumita
Updated on 15-Jan-2021 06:20:36

3K+ Views

Multiprotocol Label Switching (MPLS) is a routing technique that augments speed and control of the network traffic by directing data from one node to the next node based on short path labels. Instead of being routed using long network addresses, the data packets are routed through path labels that identify virtual paths between the nodes rather than endpoints. MPLS speeds up traffic flows by avoiding complex lookups in the routing table at each node as in conventional routing algorithms.MPLS is a scalable and protocol-independent routing technique. It works with Internet Protocol (IP), Ethernet, Frame Relay and Asynchronous Transport Mode (ATM). ... Read More

Check if Suffix and Prefix of a String are Palindromes in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:20:34

358 Views

Suppose we have a string s, we have to check whether the string palindromes as its prefix and suffix substrings or not.So, if the input is like s = "levelishighforracecar", then the output will be True as there are palindrome prefix and suffix: "level" and "racecar" respectively.To solve this, we will follow these steps −l := size of sfor i in range 2 to l + 2, doif substring of s up to index i is palindrome, thencome out from loopif i is same as(l + 1) , thenreturn Falsefor i in range 2 to l + 2, doif substring ... Read More

Check If Subarray with Given Product Exists in an Array in Python

Arnab Chakraborty
Updated on 15-Jan-2021 06:18:42

644 Views

Suppose we have an array called nums and this contains positive and negative numbers. We have another value k. We have to check whether any subarray whose product is k is present in the array or not.So, if the input is like nums = [-2, -1, 1, 3, 5, 8], k = 6, then the output will be True as the subarray is [-2, -1, 3]To solve this, we will follow these steps −minimum := nums[0], maximum := nums[0]prod_max := nums[0]for i in range 1 to size of nums - 1, doif nums[i] < 0, thenswap maximum and minimummaximum := ... Read More

Advertisements