Found 26504 Articles for Server Side Programming

Program to find nearest point that has the same x or y coordinate using Python

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

2K+ Views

Suppose we have a set of points given in an array called pts. We also have another point (x, y) which is our current location. We are defining a valid point as, a point which shares the same x-coordinate or the same y-coordinate as our current point. We have to return the index of the valid point with the smallest Manhattan distance from our current location (x, y). If there are more than one points, then return the valid point with the smallest index. (Note: the Manhattan distance between two points (a, b) and (p, q) is |a - p| ... Read More

Program to count items matching a rule using Python

Arnab Chakraborty
Updated on 29-May-2021 14:32:09

471 Views

Suppose we have an array nums, where each nums[i] contains three elements [type_i, color_i, name_i]. These are describing the type, color, and name of the ith item. We also have a rule represented by two other strings, ruleKey and ruleValue. Now we can say the ith item is matched the rule if one of the following is true −ruleKey = "type" and ruleValue = type_i.ruleKey = "color" and ruleValue = color_i.ruleKey = "name" and ruleValue = name_i.We have to find number of matching we can find.So, if the input is likeBikeblueElecBCarsilverSumoBikeblueTVSAnd ruleKey = "color", ruleValue = "blue", then the output ... Read More

Program to merge strings alternately using Python

Arnab Chakraborty
Updated on 29-May-2021 14:32:28

6K+ Views

Suppose we have two strings s and t. We have to merge them by adding letters in alternating fashion, starting from s. If s and t are not of same length, add the extra letters onto the end of the merged string.So, if the input is like s = "major" t = "general", then the output will be "mgaejnoerral", as t is larger than s, so we have added extra part "ral" at the end.To solve this, we will follow these steps −i := j := 0result := blank stringwhile i < size of s and j < size of ... Read More

Program to find longest nice substring using Python

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

587 Views

Suppose we have a string s. We have to find longest nice substring of s. For a string s, it will be said to nice when, for every letter of the alphabet in s, it appears in uppercase and lowercase both. If there are multiple such substring, then return the substring of the earliest occurrence.So, if the input is like s = "ZbybBbz", then the output will be "bBb" as this contains lowercase and uppercase B's.To solve this, we will follow these steps −cur_max:= -1res:= blank stringfor i in range 0 to size of s, doc := s[i]upper := a ... Read More

Program to find longest distance of 1s in binary form of a number using Python

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

311 Views

Suppose we have a number N, we have to find the longest distance between two consecutive 1's in its binary representation. If there are no two-consecutive 1's, then return 0.So, if the input is like 71, then the output will be 4, because 71 in binary is 1000111. Now there are four ones, and first 1 and the second 1 are at distance 4. All others are one distance away. So longest distance is 4 here.To solve this, we will follow these steps −K := make a list of bits of binary representation of NMax := 0, C := 0, ... Read More

Program to find largest perimeter triangle using Python

Arnab Chakraborty
Updated on 29-May-2021 14:14:25

555 Views

Suppose we have an array nums of positive lengths, we have to find the largest perimeter of a triangle, by taking three values from that array. When it is impossible to form any triangle of non-zero area, then return 0.So, if the input is like [8,3,6,4,2,5], then the output will be 19.To solve this, we will follow these steps −sort the list numsa := delete last element from numsb := delete last element from numsc := delete last element from numswhile b+c

while and do-while in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:23:52

248 Views

While and do-while loops are also present in Dart's arsenal. They are quite similar in terms of syntax and functionality to the C's while and do-while loops.While loopA while loop is an indefinite loop that can be modified to run for a finite number of iterations based on the condition we provide.Syntaxwhile(condition){    // do this }ExampleConsider the example shown below − Live Demovoid main() {    var age = 6;    while(age < 10){       print("age is now $age");       age++;    } }Outputage is now 6 age is now 7 age is now 8 age ... Read More

Variables in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:23:21

133 Views

Dart being a statically typed language demands that we declare the type of variable that we going to use. In simpler terms, it is necessary that we define what kind of data we are going to store in the variable before making use of it.ExampleConsider the example shown below − Live Demovoid main(){    int collegeId = 1234;    // declaring and assigning a variable    print(collegeId);        // printing the variable's value    String myName = "mukul";    print(myName); }In the above example, we declared two variables named 'collegeId' and 'myName' and assigned 1234 and "mukul" as ... Read More

Typedef in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:22:56

131 Views

In Dart, we make use of Typedef when we want to create an alias for a function type that we can use as type annotations for declaring variables and return types of that function type.A typedef holds type information when a function type is assigned to a variable.Syntaxtypedef functionName(parameters)We make use of the above syntax when we want to create a Typedef in Dart.Now, let's take a look at an example when we want to assign a typedef variable to a function in a program.typdef varName = functionNameOnce we have assigned the functionName to a typedef variable, we can later invoke the original ... Read More

This keyword in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:22:32

845 Views

This keyword in dart is used to remove the ambiguity that can be caused if the class attributes and the parameters have the same name. This keyword basically represents an implicit object pointing to the current class object.We usually prefix the class attribute with this keyword whenever we want to remove the ambiguity between the class attributes and the parameters.ExampleLet's take two examples of the case where the name of the class attribute and the parameters are the same.Consider the example shown below − Live Demovoid main() {    Employee emp = new Employee('001');    emp.empCode = '111'; } class ... Read More

Advertisements