AmitDiwan has Published 10744 Articles

Extract Unique dictionary values in Python Program

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:09:31

1K+ Views

When it is required to extract unique values from a dictionary, a dictionary is created, and the ‘sorted’ method and dictionary comprehension is used.Below is a demonstration for the same −Example Live Demomy_dict = {'hi' : [5, 3, 8, 0],    'there' : [22, 51, 63, 77],    'how' : [7, ... Read More

Count Number of Lowercase Characters in a String in Python Program

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:08:56

2K+ Views

When it is required to count the number of lower case characters in a string, the ‘islower’ method and a simple ‘for’ loop can be used.Below is the demonstration of the same −Example Live Demomy_string = "Hi there how are you" print("The string is ") print(my_string) my_counter=0 for i in ... Read More

Take in Two Strings and Display the Larger String without Using Built-in Functions in Python Program

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:08:37

805 Views

When it is required to take two strings and display the larger string without using any built-in function, the counter can be used to get the length of the strings, and ‘if’ condition can be used to compare their lengths.Below is the demonstration of the same −Example Live Demostring_1= "Hi there" ... Read More

Python Program to Find All Connected Components using DFS in an Undirected Graph

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:08:17

2K+ Views

When it is required to find all the connected components using depth first search in an undirected graph, a class is defined that contains methods to initialize values, perform depth first search traversal, find the connected components, add nodes to the graph and so on. The instance of the class ... Read More

All ways of balancing n parenthesis in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:07:54

161 Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return an array showing all the ways of balancing n parenthesis.For example, for n = 3, the output will be −["()()()", "(())()", "()(())", "(()())", "((()))"]ExampleFollowing is the code − Live Democonst res = []; ... Read More

Python Program to Calculate the Length of a String Without Using a Library Function

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:07:51

3K+ Views

When it is required to calculate the length of a string without using library methods, a counter is used to increment every time an element of the string is encountered.Below is the demonstration of the same −Example Live Demomy_string = "Hi Will" print("The string is :") print(my_string) my_counter=0 for i in ... Read More

Python Program to Remove the nth Index Character from a Non-Empty String

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:07:12

840 Views

When it is required to remove a specific index character from a string which isn’t empty, it can be iterated over, and when the index doesn’t match, that character can be stored in another string.Below is the demonstration of the same −Example Live Demomy_string = "Hi there how are you" ... Read More

Python Program to solve Maximum Subarray Problem using Kadane’s Algorithm

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:06:47

303 Views

When it is required to find the maximum sub array using Kadane’s algorithm, a method is defined that helps find the maximum of the sub array. Iterators are used to keep track of the maximum sub array.Below is the demonstration of the same −Example Live Demodef find_max_sub_array(my_list, beg, end):    max_end_at_i ... Read More

Moving all zeroes present in the array to the end in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:06:16

545 Views

ProblemWe are required to write a JavaScript function that takes in an array of literals that might contain some 0s. Our function should tweak the array such that all the zeroes are pushed to the end and all non-zero elements hold their relative positions.ExampleFollowing is the code − Live Democonst arr ... Read More

Determining sum of array as even or odd in JavaScript

AmitDiwan

AmitDiwan

Updated on 17-Apr-2021 12:04:02

422 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers arr. Our function should return the string ‘odd’ if the sum of all the elements of the array is odd or ‘even’ if it’s even.ExampleFollowing is the code − Live Democonst arr = [5, 1, 8, ... Read More

Advertisements