Forward and backward iterations in Python
Imagine your in a situation that needs to go through the elements of a list in backward order. To achieve this we need to read the last element first and then the last but one and so on till the element at index 0. Various python programming features can be used to achieve this.
list = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
for i in range( 0, len(list)) :
Revers the list:
Here list comprehension is used that is [::-1]. Here we are slicing the list which…
Problem statement: Given a string
s consisting of open and closed brackets
")", return the length of the longest substring in
s that is a valid string of parentheses.
s = ")(())(()"
"(())" is the longest substring with valid parentheses.
Naive approach: Find all the substrings of a given string. For every string, check if it is a valid string or not. If valid and length is more than maximum length so far, then update maximum length. We can check whether a substring is valid or not in linear time using a stack. …
def solve(self, matrix):
n = len(matrix)
if n <= 2:
return sum(sum(row) for row in matrix)
first_row = sum(matrix)
last_row = sum(matrix[n-1])
diagonal = sum(matrix[i][n-1-i] for i in range(1, n-1))
return first_row + last_row + diagonal
Let’s add the horizontal parts of the Z…
Question: You are given a lowercase alphabet string
text. Return a new string where every character in
text is mapped to its reverse in the alphabet, so that
x, and so on.
text = "abcdef"
Find a new string where every character in text is mapped to its reverse in the alphabet. As an example, a becomes z, b becomes y and so on.
So, if the input is like “abcdefg”, then the output will be “zyxwvut”
To solve this, we will follow these steps −
OOP is the most popular way of analysing, designing, and developing application systems, especially on complex scientific computing software systems. The perspective that views the elements of a given situation by decomposing them into objects and object relationships. This approach used to design modular and reusable software systems.
What is Object-Oriented Design?
The classical view of a computer program is that of a process that has been encoded in a form that can be executed on a computer. …
Computer Science actually came from Mathematics. Many mathematicians are programmers that have written their programs in the words of Mathematics, using mathematical notation.
As mathematicians’ problem-solving techniques became more sophisticated and the problems they were solving became more complex, they were interested in finding automated ways of solving these problems that lead to the invention of the computer.
How to do this using programming?
What on earth is a pangram?
A pangram is a sentence or expression that uses all the letters of the alphabet. … The best known pangram in English is “The quick brown fox jumps over the lazy dog,” a sentence that’s often used for touch-typing practice
Problem: Given a string
s, representing a sentence, return whether every letter (case-insensitive) of the alphabet is used at least once.
The first naive approach you will be thinking
What is the fuzz about microcontrollers?
The generic definition of a microcontroller is a small, low-cost and self-contained computer-on-a-chip that can be used as an embedded system. A microcontrollers work at clock rate frequencies, which usually include:
Microcontrollers usually must have low-power requirements since many devices they control are battery-operated. Microcontrollers are used in many consumer electronics, car engines, computer peripherals and test or measurement equipment. And these are…
Linear programming is a special case of mathematical programming, also known as mathematical optimization. Linear optimization is a mathematical programming technique to obtain the best result or outcome, like maximum profit or least cost, in a mathematical model whose requirements are represented by linear relationships.
Pillars of LP:
Lead, Product Development, Embedded System Specialist/Mad scientist