Find the Winner of an Array Game Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:57:33

1K+ Views

Suppose we have an array called arr, this contains unique elements and we also have another value k. Now consider a game where we take first two elements of the array. In each turn, we compare arr[0] with arr[1], and the larger value wins and remains at position 0 and the smaller value moves to the end of the array. This game will end when a value wins’ k consecutive rounds. We have to find the winner from the array.So, if the input is like arr = [1, 5, 6, 3, 4, 2], and k = 3, then the output ... Read More

Minimum Insertions to Balance a Parentheses String Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:57:14

813 Views

Suppose we have a string s with opening and closing parenthesis '(' and ')'. We can say a parentheses string is balanced when −Any left parenthesis '(' have a corresponding two consecutive right parenthesis '))'.A Left parenthesis '(' must go before the corresponding two consecutive right parenthesis '))'.So for example, "())", "())(())))" are balanced but ")()", "()))" are not. If we have such string, we have to count number of parenthesis (opening or closing) to make string balanced.So, if the input is like s = "(())))))", then the output will be 1 because if we split it up, we can ... Read More

Check Equivalence of Two Expression Trees in Python

Arnab Chakraborty
Updated on 29-May-2021 13:56:21

245 Views

Suppose, we are provided two expression trees. We have to write a program that checks the two expression trees and determines if the expression trees generate similar values. The two expression trees are provided to us in an in-order manner and we return a True value if they match, or else we return a False value.So, if the input is likethen the output will be True.The two expression trees evaluate to the same value.To solve this, we will follow these steps:Define a function dfs() . This will take node, dicif node is empty, thenreturnif left of node and right of ... Read More

Make a Bulb Switcher Using Binary String in Python

Arnab Chakraborty
Updated on 29-May-2021 13:55:18

1K+ Views

Suppose we have n bulbs in a room, these bulbs are numbered from 0 to n-1. We have to arrange them in a row from left to right. Initially, all the bulbs are turned off (0-state). We have to get the configuration represented by given target array 't' where t[i] is '1' if the ith bulb is on and '0' if it is off. We also have a switch to flip the state of the bulb. And flipping operation is defined as follows −Select any bulb index i.Flip each bulb from index i to index n - 1.We have to ... Read More

Find Number of Good Leaf Nodes Pairs Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:54:36

322 Views

Suppose we have a binary tree. and another value distance d. A pair of two different leaf nodes are said to be good, when the shortest path between these two nodes is smaller or same as distance d.So, if the input is likeAnd distance d = 4, then the output will be 2 because the pairs are (8, 7) and (5, 6) as their path length distance is 2, but (7, 5) or (8, 6) or other pairs are not good as their path length is 5 which is larger than d = 4To solve this, we will follow these ... Read More

Find Minimum Swaps to Arrange a Binary Grid Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:52:45

324 Views

Suppose we have a n x n binary matrix. We can perform an operation on it like, at one step we select two adjacent rows and swap them. We have to count number of minimum swaps required, so that all nodes above the major diagonal of the matrix is 0. If there is no such solution, then return -1.So, if the input is like010011100then the output will be 2 because −To solve this, we will follow these steps:n := row count of matrixm := make an array of size n and fill with nfor i in range 0 to n ... Read More

Understanding Arduino Uno Pinout

Yash Sanghvi
Updated on 29-May-2021 13:51:31

643 Views

The Arduino Uno board looks like the following −As you can see, the pins are broadly divided into 3 sections. Two sections at the bottom of the image, and one at the top.Let us look at the bottom sections.Section 1The first section contains power pins.The Vin pin can be used if you are using an external power source (and not the USB) to power the board. The recommended voltage range is 7-12 V.The 3.3V and 5V pins provide 3.3V and 5V outputs respectively, and should be used to power other components using the Arduino board. The maximum current from the ... Read More

Store a New File in SD Card Connected to Arduino

Yash Sanghvi
Updated on 29-May-2021 13:51:08

737 Views

In this tutorial, we will create a new file in an SD Card connected to Arduino Uno.Circuit DiagramThe circuit diagram is shown below −As you can see, you need to make the following connections −SD Card HolderArduino UnoVcc5VGNDGNDMISO12MOSI11SCK13CS10Only for the Vcc, make sure that your SD Card Holder takes 5V as input. If it takes in 3.3V, connect it to the 3.3V pin on Arduino Uno.Code WalkthroughWe will be walking through the example code that comes in with the inbuilt SD library. You can access it from File → Examples → SD → DataloggerAlternatively, you can access the code on ... Read More

List Files Stored in SD Card Connected to Arduino

Yash Sanghvi
Updated on 29-May-2021 13:50:45

5K+ Views

As the title suggests, in this tutorial, we will be listing the files stored in an SD Card connected to Arduino.Circuit DiagramThe circuit diagram is shown below −As you can see, you need to make the following connections −SD Card HolderArduino UnoVcc5VGNDGNDMISO12MOSI11SCK13CS10Only for the Vcc, make sure that your SD Card Holder takes 5V as input. If it takes in 3.3V, connect it to the 3.3V pin on Arduino Uno.Code WalkthroughWe will be walking through the example code that comes in with the inbuilt SD library. You can access it from File → Examples → SD → listfilesAlternatively, the code ... Read More

Read a File from SD Card Connected to Arduino

Yash Sanghvi
Updated on 29-May-2021 13:50:20

2K+ Views

As the title suggests, in this tutorial, we will read a file from an SD Card connected to Arduino.Circuit DiagramThe circuit diagram is shown below −As you can see, you need to make the following connections −SD Card HolderArduino UnoVcc5VGNDGNDMISO12MOSI11SCK13CS10Only for the Vcc, make sure that your SD Card Holder takes 5V as input. If it takes in 3.3V, connect it to the 3.3V pin on Arduino Uno.Code WalkthroughWe will be walking through the example code that comes in with the inbuilt SD library. You can access it from File → Examples → SD → ReadWriteAlternatively, you can find the ... Read More

Advertisements