## Is there a better way to iterate through a dict while comparing against a list of values?

Consider a fixed list of keys and a dictionary of random key/values. I have to iterate through the dictionary and if a key is not in the list (keys that may or may not exist in the dictionary), then I …

## Checking for a strong password fails for a case it shouldn’t

I am working through Leetcode problem 420. Strong Password Checker. This is the problem statement: A password is considered strong if the below conditions are all met: It has at least 6 characters …

## set a boolean variable to true and another ones to false in javascript?

I want to know if there is way I can simplify this code: switch(visibleMenu) { case “menu”: { mainMenu = true; assignment = false; …

## How to remove numbers from a list which contain repeated digits?

I am trying to solve the following problem: I have a pretty long list of integer numbers in a given range, most of them contain numbers with repeated digits like in the example below. [123456, 889756, …

## Maze pathfinding implementation (BFS) not giving correct path

I am trying to get the shortest path for a maze with a ball (the ball is rolling until it hits a wall). maze = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, …

## Optimal coalition structure

The problem is the following: if there is a set S = {x1, …, x_n} and a function f: set -> number, which takes a set as an input and returns a number as an output, what is the best possible …

## When algorithm is placed inside loop it produces different results, C++

I create the following algorithm in Rcpp and compile it in R. // [[Rcpp::depends(RcppArmadillo)]] #include // [[Rcpp::export]] arma::colvec Demo(arma::mat n, …

## Creating functions in a loop with names depends on the iterable

My goal : get the digit in the position i from a number x with a function called ni. e.g : ( i = 3 , and x = 12345 ) => n3(12345) == 4. My task surrounds a lot of number manipulation and I can have …

## count repeated elements in a string

The question is to find the number of consecutive occurrences of a character ‘*’ in a string. I’ve written a program for it but is there any other efficient way to solve this for(int i=0;i<...

## Smallest path from corner to corner of a 2D array

I’m working on a problem where I’m trying to get from the top left corner, i.e. (0,0), to the bottom right, or (m – 1, n – 1), of an input m x n 2D array. Additionally, each element of the array …