All Questions
Tagged with programming-challenge python
1,025 questions
2
votes
0
answers
1k
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
417
views
Euler Project: Sums of Digit Factorials
MY CODE:
...
1
vote
2
answers
120
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
1k
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
282
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
159
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
550
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
328
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
735
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
273
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
240
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
683
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
255
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
4k
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
1k
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
1k
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
469
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
238
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
188
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
208
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
1k
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,...
3
votes
1
answer
523
views
Programming Challenge - Game Scoring
Can this solution be made more efficient?
game_scoring.py
...
11
votes
2
answers
2k
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
751
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
2k
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
299
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/...
1
vote
1
answer
161
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 ...
0
votes
1
answer
95
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
81
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
1
answer
1k
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
670
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
543
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
224
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
115
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
889
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. ...
-2
votes
1
answer
69
views
leetcode 169 optimzations reducing complexity [closed]
This is for leetcode problem: https://leetcode.com/problems/majority-element
There is something wrong with the way I create solutions, and not sure how to stop doing it. Basically the problem is I ...
2
votes
1
answer
171
views
CodeChef - Red Alert
I have solved this problem from the CodeChef platform using the Python prorgamming language
Here is the code:
...
2
votes
1
answer
996
views
Find the closest match to a string [closed]
Input
The first line of input contains a string s: the word misspelled
by your partner. Assume that your partner did not add or remove any
letters; they only replaced letters with incorrect ones. The ...
3
votes
2
answers
286
views
Drug Analyzer challenge
What do I need help with?
I'm doing the challenge below, in which I need to increase code performance. It's currently at 63% and I need to increase it to at least 71% however I can't optimize more ...
3
votes
1
answer
340
views
ZigZag Conversion Coding Challenge
This is my solution for ZigZag Conversion, a coding challenge from LeetCode.
The challenge:
Write a program that takes two parameters, a string and a number of
rows, that interprets the string as if ...
1
vote
1
answer
205
views
Rock paper scissors coding assignment
I had a coding assignment to write a Rock Paper Scissors game. The main task is not to show a solution but rather to test the coding style. The rules are such:
Problem:
rock is "O", paper is ...
4
votes
3
answers
176
views
HackInScience exercise: Sequence Mining
I am working on a practice problem found here: https://www.hackinscience.org/exercises/sequence-mining
Overview
Sequence mining is useful for analyzing list of events when order matters. It's used ...
0
votes
1
answer
261
views
Climbing the leaderboard (Hacker Rank) via binary search
I am trying to solve the Climbing the leaderboard problem on Hacker Rank. My code passes all the test cases except Test Cases 6 to 9, which I assume are using large data sets.
I'm using binary search ...
1
vote
2
answers
121
views
Search for text in a file
I have this implementation of Grep where I use re.search:
...
4
votes
2
answers
199
views
Bisection, linear recurrences and even Fibonacci numbers
So this code is yet another attempt at solving the second Project Euler problem to improve my handling of Python. The purpose of the code is to solve the problem below
Each new term in the Fibonacci ...
10
votes
4
answers
3k
views
First non-repeating Character, with a single loop in Python
I recently tried to solve the first non-repeating character problem. Please tell me if my solution is valid. I'm aiming for O(n) with a single loop.
My thinking is, it would be easy to tell you what ...
1
vote
2
answers
206
views
Permuted multiples in python
How can I improve efficiency/readability of the following code?
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the ...
1
vote
1
answer
368
views
Google Foobar challenge optimization
I am trying to solve Google Foobar challenge prepare-the-bunnies-escape using my own approach, instead of BFS. I attempt to solve two ends of the maze and try to ...