Find Second Largest Digit in a String Using Python

Arnab Chakraborty
Updated on 29-May-2021 14:31:05

1K+ Views

Suppose we have an alphanumeric string s, we have to find the second largest numerical digit that appears in s, if there is no such string then return -1.So, if the input is like s = "p84t3ho1n", then the output will be 4 as the digits are [1,3,4,8], so second largest digit is 4.To solve this, we will follow these steps −lst := a new setfor each let in s, doif let is not alphabetic, theninsert let as integer in lstif size of lst

Find Maximum Ascending Subarray Sum Using Python

Arnab Chakraborty
Updated on 29-May-2021 14:30:50

644 Views

Suppose we have an array of positive values called nums, we have to find the maximum possible sum of an ascending subarray in nums. We can say a subarray [nums_l, nums_l+1, ..., nums_r-1, nums_r] is ascending when for all i where l nums[i-1], thentotal := total + nums[i]otherwise, total:= nums[i]if total > max_total, thenmax_total:= totalreturn max_totalLet us see the following implementation to get better understanding −Example Live Demodef solve(nums):    total=nums[0]    max_total=nums[0]    for i in range(1, len(nums)):       if nums[i] > nums[i-1]:          total+=nums[i]       else:          total=nums[i] ... Read More

Get Max and Min Values of an Array in Arduino

Yash Sanghvi
Updated on 29-May-2021 14:29:15

10K+ Views

In order to get the max/ min values of an array in Arduino, we can run a simple for loop. Two implementations are shown below. One uses the max() and min() functions of Arduino, and the other uses the > and < operators.The max and min functions have the following syntax: max(a, b) and min(a, b), and they return the max and min values out of a and b respectively.Implementation 1 − Using > and < operatorsvoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    int myArray[6] = {1, 5, -6, ... Read More

Exponential Expressions in Arduino

Yash Sanghvi
Updated on 29-May-2021 14:28:57

5K+ Views

The pow() function of Arduino can be used for evaluating exponential expressions. Any expression of the form ab can be expressed as pow(a, b). For example 23 becomes pow(2, 3).The type for both the base (a) and the exponent (b) is float. This function returns a double.Examplevoid setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    float base = 2;    float exponent = 3;    Serial.println(pow(base, exponent)); } void loop() {    // put your main code here, to run repeatedly: }OutputThe Serial Monitor Output is shown below −You are ... Read More

Wattmeter Types and Working Principle

Manish Kumar Saini
Updated on 29-May-2021 14:28:33

23K+ Views

A wattmeter is an instrument which is used to measure electric power given to or developed by an electrical circuit. Generally, a wattmeter consists of a current coil and a potential coil.Types of WattmeterElectrodynamometer wattmeter – for both DC and AC power measurementInduction wattmeter – for AC power measurement onlyWorking Principle of Electrodynamometer WattmeterThe electrodynamometer wattmeter works on the dynamometer principle i.e. a mechanical force acts between two current carrying conductors or coils.It consists of a fixed which is divided into two halves which are parallel to each other and is connected in series with the load while the moving ... Read More

Basic AnalogRead in Arduino Program

Yash Sanghvi
Updated on 29-May-2021 14:27:05

712 Views

Converting analog values to digital is a common requirement from microcontrollers in general, and Arduino is no different. Arduino IDE has a built-in analogRead function to facilitate the conversion of analog values to digital.From the programming perspective, the only thing you require to know is the pins of your microcontroller that support ADC. On the Arduino UNO board, the pins A0 to A5 support ADC.Now, let us assume that you’ve connected your A0 pin to an analog wire (maybe the junction between an LDR and a resistor, or the central leg of a potentiometer).The basic Arduino code to print the analog ... Read More

Bitwise AND and OR in Arduino

Yash Sanghvi
Updated on 29-May-2021 14:26:50

1K+ Views

Bitwise AND/ OR means AND/ OR performed at a bit-level, individually. Each number has its binary representation. When you perform the bitwise AND of one number with another, the AND operation is performed on the corresponding bits of the two numbers. Thus, LSB of number 1 is ANDed with the LSB of number 2, and so on.The bitwise AND operation in Arduino is & and the bitwise OR operator is |.Syntaxa & bfor AND.a | bfor OR.The truth table for AND isPQp & q000010100111The truth table for OR is −PQp & q000011101111Since these are bitwise operators, we need to perform ... Read More

Find Number of Different Integers in a String Using Python

Arnab Chakraborty
Updated on 29-May-2021 14:17:19

421 Views

Suppose we have a lowercase alphanumeric string s. We shave to replace every non-digit character with a space, but now we are left with some integers that are separated by at least one space. We have to find the number of different integers after performing the replacement operations on s. Here two numbers are considered as different if their decimal representations without any leading zeros are different.So, if the input is like s = "ab12fg012th5er67", then the output will be 3 because, there are few numbers ["12", "012", "5", "67"] now "12" and "012" are different in string but same ... Read More

Determine Color of a Chessboard Square Using Python

Arnab Chakraborty
Updated on 29-May-2021 14:17:01

2K+ Views

Suppose we have a chessboard coordinate, that is a string that represents the coordinates of row and column of the chessboard. Below is a chessboard for your reference.We have to check whether given cell is white or not, if white return true, otherwise return false.So, if the input is like coordinate = "f5", then the output will be True (See the image)To solve this, we will follow these steps −if ASCII of coordinate[0] mod 2 is same coordinate[1]) mod 2, thenreturn Falseotherwise, return TrueLet us see the following implementation to get better understanding −Example Live Demodef solve(coordinate):    if (ord(coordinate[0]))%2 == ... Read More

Find K Partitions After Truncating Sentence Using Python

Arnab Chakraborty
Updated on 29-May-2021 14:16:46

123 Views

Suppose we have sentence s where some English words are present, that are separated by a single space with no leading or trailing spaces. We also have another value k. We have to find only the first k words after truncating.So, if the input is like s = "Coding challenges are really helpful for students" k = 5, then the output will be True (See the image)To solve this, we will follow these steps −words := split s by spacesjoin first k letters from words array by separating spaces and returnLet us see the following implementation to get better understanding ... Read More

Advertisements