Sign in

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…

Problem statement: Given a string s consisting of open and closed brackets "(" and ")", return the length of the longest substring in s that is a valid string of parentheses.

Example 1


s = ")(())(()"




"(())" is the longest substring with valid parentheses.

Naive approach: Find all…


Simple algorithm

  • n := row count of matrix
  • if n <= 2, then
  • return sum of all elements in matrix
  • first_row := sum of first row
  • last_row := sum of last row
  • diagonal = sum of matrix[i, n-1-i] for all i from 1 to n-2
  • return first_row + last_row…

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 a becomes z, b becomes y, c becomes x, and so on.

Example 1


text = "abcdef"




Find a new…

Given two integers x, and y return the number of positions where their values differ in their binary representations as a 32-bit integer.

Example 1


x = 9
y = 5

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…

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…

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. …

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:

  • An 8 or 16 or 32 or 64 bit microprocessor.
  • A little measure…

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:

  • Objective Function…

Iqram Ali

Lead, Product Development, Embedded System Specialist/Mad scientist

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store