All Questions
Tagged with programming-challenge python
992
questions
3
votes
1
answer
71
views
Validating a Sudoku Board in Python
The problem statement is as follows:
Sudoku is a game played on a 9x9 grid. The goal of the game is to fill
all cells of the grid with digits from 1 to 9, so that each column,
each row, and each of ...
4
votes
3
answers
108
views
Improving efficiency of Rust algorithm ported from Python generator
I'm learning Rust by solving ProjectEuler problems.
To this end, I am trying to port a solution to problem 88 (link) in Python that heavily relies on generators to Rust (which doesn't have generators)....
1
vote
1
answer
324
views
sum of intervals kata in codewars
instructions for the kata:
Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only ...
0
votes
1
answer
92
views
Permutations CodeWars problem solved!
i have solved a question in codewars:
https://www.codewars.com/kata/5254ca2719453dcc0b00027d/python
, here's my solution is it unefficient to use itertools because people are blaming that is cheating ...
0
votes
1
answer
200
views
Calculate score of rock-paper-scissors (Advent of Code 2022: Day 2)
Advent of code, Day 2.
Here is my code.
Less verbose version of the question follows.
...
3
votes
1
answer
150
views
Finger Exercise: Update book cipher by creating new book
I'm working my way through the finger exercises in John Guttag's book Introduction to Python Programming, third edition. The following finger exercise on page 143 describes encryption/decryption with ...
6
votes
2
answers
757
views
Find all combinations of length 3 whose sum is divisible by a given number
I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size.
The problem: Given a list ...
4
votes
1
answer
202
views
Leetcode, longest palindromic substring
Here's a link
Given a string s, return the longest palindromic substring in s. A string is called a palindrome string if the reverse of that string is the same as the original string.
Example 1:
...
1
vote
2
answers
183
views
Find the cheapest flight to reach from source to destination
As the input you get the flight schedule as an array, each element of which is the price of a direct flight between 2 cities ...
3
votes
3
answers
382
views
Creating Phone Number challenge from Code Wars
I solved a question on Codewars about creating a phone number:
Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone ...
5
votes
1
answer
187
views
Connecting ropes with minimum cost
Question:
There are given N ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes ...
3
votes
0
answers
83
views
Finding the number of possible paths in a cave system (Python)
I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
2
votes
0
answers
477
views
Determining the winning bingo from a set of bingo boards and sequence of draws
I've learned Python basics about two years ago and did a few personal projects, one big one that turned out to be useful in my line of work, a few small programs for my hobbies and I've also began ...
3
votes
2
answers
232
views
Euler Project: Sums of Digit Factorials
MY CODE:
...
-1
votes
1
answer
56
views
Sum of differences between products and LCMs
I've been trying to solve this Codewars problem https://www.codewars.com/kata/56e56756404bb1c950000992
In this kata you need to create a function that takes a 2D array/list of non-negative integer ...
4
votes
2
answers
586
views
Hangman Game: Revealing guessed letters
I solved this problem: the Edabit Hangman Game challenge.
Create a function that, given a phrase and a number of letters guessed, returns a string with hyphens - ...
4
votes
1
answer
107
views
Decibinary for xth number (Python code)
I created the code for the problem description below. It works for \$N\le10^6\$ but after that it gives a time out error. What I don't understand is how to optimize the code using dynamic programming. ...
4
votes
1
answer
107
views
Time limit error in 'The Minion Game' using python in Hacker Rank
This is the question link for the quick reference.
Problem :
There are two players Kevin and Stuart have to play a game in which they're pleased to create multiple strings and will get +1 score for ...
4
votes
2
answers
351
views
Geektrust coding challenge: simulating a marketplace for loans
This is the my solution to a coding challenge in Geektrust. The question is linked here.
A shortened version would be as follows.
The aim is to simulate a marketplace for banks to lend money to ...
4
votes
2
answers
193
views
Counting primes less than n in Python
I implemented (a refinement of) the Sieve of Eratosthenes for counting primes less than a given number n. This is a coding exercise from LeetCode. The class Solution...
3
votes
2
answers
220
views
MP3 Playlist Class in Python
Background Info
I am an intermediate level Python programmer. This is my implementation of a MP3 Playlist class challenge that was hosted on 101 Computing.Net. The ...
4
votes
1
answer
143
views
Python program for the Longest Substring Without Repeating Characters
I write my Python program below for this Leetcode problem:
Given a string s, find the length of the longest substring without repeating characters.
Example 1:
...
9
votes
3
answers
3k
views
Determine if Hill or Valley
This is my accepted submission for LeetCode. The problem is
You are given a 0-indexed integer array nums. An index i is part of ...
0
votes
1
answer
110
views
Largest product in a series
Problem description:
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
73167176531330624919225119674426574742355349194934
...
2
votes
3
answers
1k
views
the 10001st prime number
Problem description:
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
What is the 10001st prime number?
Prime number:
A prime number is a whole ...
3
votes
1
answer
287
views
LeetCode 68. Text Justification
I am trying out Leetcode problem 68 and I need your help to asses the code. I am pretty new to this.
Given an array of strings words and a width ...
0
votes
2
answers
165
views
Sum square difference
Problem description:
The sum of the squares of the first ten natural numbers is,
1² + 2² + … + 10² = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + … + 10)² = 55² = 3025
Hence ...
2
votes
1
answer
2k
views
The smallest positive number that is evenly divisible by all of the numbers from 1 to 20
Problem description:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of ...
3
votes
3
answers
556
views
The largest palindrome made from the product of two 3-digit numbers
Problem description:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the ...
4
votes
2
answers
478
views
Calculate the first largest factor of 600851475143
ٍProblem description:
The prime factors of 13195 are 5, 7, 13 and 29. Largest prime factor 13195 is 29.
What is the largest prime factor of the number 600851475143 ?
Prime Factor:
any of the prime ...
1
vote
0
answers
148
views
PyQt6 program that lets you adjust the HSV values of an RGB color
I don't know how to actually describe what this script does concisely.
I am writing GUI programs using PyQt6, and I want the most beautiful palette for my programs, so I browsed Wikipedia for a bunch ...
3
votes
1
answer
126
views
Python 3 number convertor that converts floats between decimal and bases 2-36
This is a Python 3 script that converts any real number (ints and floats) from decimal notation to any positional number system ...
2
votes
1
answer
80
views
follow-up - Checking Nested Bracket Levels in Strings Programming Challenge
A follow-up to this question, this post improves on test case issues.
To restate problem parameters, a given string S is considered closed if it:
Has a matching ...
3
votes
2
answers
187
views
Programming Challenge - Capturing Bracket Levels
I don't have a formal description for this problem, but here are the parameters:
Given a string S check that each opening bracket has a matching closing bracket.
...
2
votes
2
answers
187
views
Programming Challenge: Python 3 DNS query resolver using socket
This is a DNS query resolver written in Python 3 using socket, I wrote it entirely by myself, it supports 8 primary DNS query types: A, NS, CNAME, SOA, PTR, MX, TXT,...
2
votes
1
answer
322
views
Programming Challenge - Game Scoring
Can this solution be made more efficient?
game_scoring.py
...
11
votes
2
answers
1k
views
Calculator using variable names
I've recently been assigned an assignment to create a word calculator, and given my knowledge in python is still quite lacking, I want to ask if anybody has any better ideas for any possible solutions....
6
votes
1
answer
608
views
LFU Cache implementation in Python 3
Need some feedback on this implementation of LFU cache in python3.
Original problem : https://leetcode.com/problems/lfu-cache/
Would really appreciate some feedback on readability, understandability ...
10
votes
4
answers
950
views
Wordle puzzle game
I am a beginner programmer with not much experience, the little I do have is with Python specifically.
With all the fuss going around about the popular word game "Wordle" I wanted to ...
2
votes
3
answers
170
views
Kattis Battle Simulation
I have a working program for a problem, but need to optimize it in a way where the processing time is less than 3 seconds. This is where I found the problem:
https://open.kattis.com/problems/...
0
votes
1
answer
129
views
Extract and write fasta files using Biopython based on input from another file
I have the below code that takes a sequence file and another file with a list of contigs and extracts the sequences and writes them to a file, specifically based on the file with the contig list. The ...
-1
votes
1
answer
81
views
Codewars Runtime Error
I am currently trying to solve the problem "Is my friend cheating?" on Codewars. The Text are the Details to the Problem:
A friend of mine takes the sequence of all numbers from 1 to n (...
3
votes
0
answers
73
views
Advent of Code 2021: day 10- Syntax Scoring
The following code solves day 10 in the advent of code challenge.
The goal for this time around is evaluating whether a line of brackets
is complete, has a syntax error or is missing some closing ...
1
vote
0
answers
115
views
String search using Rabin-Karp algorithm
I am trying to solve a needle in haystack using Rabin-Karp algorithm, but for large inputs my code takes way too long time. Here is the part which apparently is too slow:
...
1
vote
1
answer
602
views
HackerRank - Climbing the Leaderboard: I don't understand why my code is exceeding the time limit
Climbing the Leaderboard
An arcade game player wants to climb to the top of the leaderboard and
track their ranking. The game uses Dense Ranking, so its leaderboard
works like this:
The player with ...
5
votes
2
answers
370
views
DNA Challenge from CS50
Added the problem link below and my implementation of it. Took me a few hours to program. I have added comments to explain my thought process.
Problem Link
Goal - To implement a program that ...
3
votes
3
answers
454
views
Find the average score, given data in a table with labeled columns not in a fixed order
I was on Hacker Rank for the first time and there was a question that required to get the inputs from STDIN and use collections.namedtuple(). It was my first time ...
6
votes
2
answers
210
views
Container with most water, with pre-computation of possible bounds
Here's my attempt at leetcode's container with most water.
Problem:
Given n non-negative integers a1, a2, ..., an , where each represents
a point at coordinate (i, ai). n vertical lines are drawn ...
1
vote
0
answers
104
views
Python functions to serialize nested data structures human readably
See Serializing (nested) data structures in a human-readable format for more details.
In the last two days I have significantly improved my function, and wrote seven implementations of it.
I have ...
5
votes
3
answers
686
views
Counting swaps in a sequence sorting algorithm
I have been working on this question, https://open.kattis.com/problems/sequences.
You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are n ‘?’s. ...