Category "for-loop"

Mini-Max Sum In JavaScript - How to Get the Minimum Sum And Maximum Sum of 4 Elements in a 5-Element Array

Link to HackerRank Challenge My idea is to loop through the array and sum all elements in the array except for one element each time, then find the smallest su

Issue when selecting desired elements from dict_keys in Python

I have a list of disctionary keys ['A_report1', 'A_report2', ..., 'A_report10','B_report1', 'B_report2', ..., 'B_report10',]. I want to extract all 'report1' fr

Comparing two panda dataframes with different size

I want to compare two dataframes with content of 1s and 0s. I run for loops to check every element of the dataframes and at the end, I want to replace the "1" v

Codility CyclicRotation Javascript Solution: Empty array returns an error

I am trying to solve this problem in codility. My solution passed all the tests except for one with empty array and rotation of 1 as arguments. I'm someway lost

Program to find number of elements between two elements a and b (where a and b both are inclusive)

Given an unsorted array of size n, write a program to find number of elements between two user-defined elements a and b (where a and b both are inclusive) of a

How do I efficiently find which elements of a list are in another list?

I want to know which elements of list_1 are in list_2. I need the output as an ordered list of booleans. But I want to avoid for loops, because both lists have

Mutiple iterators in for loop Java not working properly

I am trying to pass a Javascript code to Java, but I've got a problem with the for loop, I have a for with 2 iterators in my Javascript code, and it is working

Octave - fskipl: invalid stream number

I've got the error message: "Invalid parameter list" from my function, which let Octave open a text file and read it to get input data for my work. function [m

Python: For loops print only last element of a list

I am using a shared webspace and I can't install the dotenv libiary for php, but I can use the dotenv libiary for python to call enviorment variables from outsi

Python Count Letters in Word

I am looking to complete this code but cannot get it to execute the right way. The program connects two user-inputted names into one full name and then looks fo

IndexError: list index out of range in for loop

I write a code in python but I faced this error : if a1[i] == a1[i+1] == a1[i+2]: IndexError: list index out of range I write an if condition that if my list l

Codewars Challenge - JavaScript - Find the first non-consecutive number in Array

Link to Codewars challenge This is very basic, but for some reason, I can't figure out why I'm not able to return null when there are not any non-consecutive n

Python single plot in a for loop without creating a list or array

This may sound like a very naive question. However, to me, it's quite fundamental: Can python plot variables without putting them into arrays or lists? I couldn

program to find the sum of the first N odd numbers

I'm trying to make a program that calculates the sum of the first N odd numbers. where N is the number of the first odd numbers (e.g. N=4, then the first odds a

Create new numpy array by duplicating each item in an array

I would like to create a new numpy array by repeating each item in another array by a given number of times (n). I am currently doing this with a for loop and .

How do you remove duplicate values in array in Python?

I have an array where each element is the mean of a set of random numbers. I want to be able to remove duplicate values in this array. How would I go about doin

Function to see if word is isogram

An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only le

How to find or count the duplicate in multidimensional array in c# [closed]

I am creating a 2d (3 * 3) array in c# which has to count or find the duplicate value int[,] arr = new int[3, 3] { {1, 2, 6}, {4, 1, 5}

How to start iterating a file at specific line?

I’m iterating through a file’s lines with enumerate(), and sometimes would need to start the iterating at a specific file line, so I attempted testf

How to get value printed on Postgres

I have a requirement to translate it to an SQL script. I am using the information schema to get all the columns of a table and print their distinct count. I was