Questions tagged [programming-challenge]

Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.

Filter by
Sorted by
Tagged with
0
votes
1answer
22 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
0answers
48 views

Optimizing my code for Project Euler+ problem #1 on HackerRank

The Project Euler contest is ongoing on HackerRank and the first problem is finding out the sum of multiples of 3 and 5 below a certain number N. Two of the hidden test cases fail when I execute my ...
0
votes
0answers
43 views

Leetcode #462 (Minimum Number of Arrows to Burst Balloons), with and without optimization

I have an interesting optimization and I want to get some confirmation on whether it's valid: I was solving Leetcode #452: Minimum Number of Arrows to Burst Balloons (description in footnote [1]) and ...
12
votes
3answers
7k views

Find total number of phone numbers formed by the movement of Knight and Bishop on keypad

I recently took a test on HackerRank, and submitted my answer for the following question. I passed all the test cases but company told me that the answer is not efficient, and they are not moving ...
1
vote
0answers
29 views

AdventofCode 2021: Day 3 Solution

I am beginner to Haskell. Here is my solution to Advent of Code 2021 Day 3. Let me know what you think. I was looking at the transpose function and decided not to use head & tail function. Given ...
0
votes
0answers
64 views

Project Euler 1, 2 and 3: Functional Programming style using F#

After doing about 50 Project Euler problems in my "native" language (C#) I decided to redo some of the problems I did many years ago in F#, as it's a language I always want to give a go. ...
1
vote
2answers
110 views

Function wrapper that prints the result

(English) I was recently challenged to make a simple program that does the following: Function f accepts as a parameter a function g, which returns a value. Function f must return a function h which ...
0
votes
0answers
29 views

Hackerrank's New Year Chaos problem (find minimum number of swaps to reach a permutation)

I am trying to solve the problem to Hacker Rank's New Year chaos problem. I have come up with a not so elegant solution. This is failing to adhere to the timing constraints of Hackerrank My approach ...
2
votes
3answers
100 views

567: Permutation in String

So I've been working on this for a few days actually. I implemented a solution to the LeetCode problem: 567. Permutation in String The Problem Given two strings s1(queryStr) and s2(sourceStr), return ...
5
votes
1answer
2k views

Hackerrank: Sherlock and anagram

Problem statement Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings. Input Format First line contains \$T\$, the number of testcases. Each testcase ...
4
votes
1answer
67 views

Another Sliding Window - find each `k-size` window the maximum num. from an integer array/list

I've searched this site and find many similar questions, but not exactly the same as the one I'll post. This attempts to solve Leetcode 239: You are given an array of integers ...
0
votes
1answer
34 views

Advent of Code 2021 Day 4: Play Bingo against a Giant Squid

[This is my first post here - though I have been lurking in the back reading, plussing, and hopefully learning for over two years] Below is my solution for Advent of Code 2021 Day 4, where you are ...
1
vote
1answer
320 views

Coin Flip Streaks script

I am attempting to complete the coin flip streaks problem from automate the boring stuff with python. My code works fine but my only concern is the phrasing of the task. Does the question want us to ...
0
votes
0answers
18 views

Efficient algorithm to track all the direct parents and transitive parents(parents of parents and grand parents) in a directed acyclic graph

I am preparing for online coding assessment, where I have come across a question to write an algorithm to find the list of direct parents and transitive parents for each vertex in a directed acyclic ...
-1
votes
1answer
73 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
1answer
53 views

Project Euler problem 11 in Rust: largest product of consecutive elements in a grid

I wrote the following Rust code for euler project problem 11. It works and a small test is included, but I am not very happy about the code. At first I wanted to chain together iterators for all the ...
11
votes
2answers
1k views

Sum of Even Fibonacci numbers in functional programming

I want to solve this problem in functional programming (fp) way only. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...
4
votes
2answers
114 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 ...
4
votes
3answers
1k views

Project Euler # 20 factorial digit sum in Python

n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the digits ...
3
votes
1answer
310 views
1
vote
0answers
84 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: ...
3
votes
3answers
5k views

Google Foobar bomb_baby

This is the question I am facing at level 3 of Google Foobar: There are two types: Mach bombs (M) and Facula bombs (F). The bombs, once released into the LAMBCHOP's inner workings, will ...
8
votes
2answers
4k views

Python Amazon Checkmate

Found this challenge on CodeFights and would love a review of my style. Description An amazon (also known as a queen+knight compound) is an imaginary chess piece that can move like a queen or a ...
7
votes
2answers
6k views

BFS shortest path for Google Foobar "Prepare the Bunnies' Escape"

This is the Google Foobar puzzle "Prepare the Bunnies' Escape": You have maps of parts of the space station, each starting at a prison exit and ending at the door to an escape pod. The map ...
5
votes
2answers
5k views

BFS shortest path for Google Foobar challenge "Prepare the Bunnies' Escape"

This is the Google Foobar challenge "Prepare the Bunnies' Escape": You have maps of parts of the space station, each starting at a prison exit and ending at the door to an escape pod. The map is ...
3
votes
0answers
60 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 ...
3
votes
1answer
73 views

Efficiently calculating perfect powers in Haskell

I'm trying to calculate perfect powers to solve this code wars challenge: https://www.codewars.com/kata/55f4e56315a375c1ed000159/haskell The number 81 has a special property, a certain power of the ...
3
votes
1answer
81 views

2021 Advent of Code, Day 1 Part 2: Keeping error-handling simple while chaining iterators with Rust

This question is with respect to Day 1, Part 2 of the 2021 Advent Of Code challenge, which requires comparing values from a rolling window taken from integers streamed as input. This answer is correct,...
4
votes
1answer
217 views

Project Euler # 53 Combinatoric selections in Python

There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 In combinatorics, we use the notation, 5C3=10. In general, nCr = n! / r! (n−r)!, ...
2
votes
1answer
107 views

Returning maximum number of consecutive 1s in list of binary numbers

This is what I implemented in Rust to get the maximum number of consecutive 1s in list of binary numbers. ...
1
vote
1answer
454 views

Leetcode 210. Course Schedule II

Problem statement There are a total of \$n\$ courses you have to take, labeled from \$0\$ to \$n - 1\$. Some courses may have prerequisites, for example to take course \$0\$ you have to ...
4
votes
1answer
148 views

Advent of Code 2021: day 1

I am doing the Advent of Code challenge to learn Rust (obviously there may be spoilers if you still want to do the challenge). The instructions are too long to include verbatim so I will link them and ...
3
votes
0answers
146 views

Advent of Code 2021, Day 3 in Haskell

This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal. ...
3
votes
1answer
91 views

Reading input in idiomatic Rust for Advent of Code Day 2

I'm trying to write idiomatic and fast Rust code by solving AoC challenges this year! :-) Link to AoC Day 2 problem The input format in this problem is a list of lines each containing one string token ...
1
vote
0answers
44 views

Euler Project Problem #3 Optimization Needed

Well I was solving Problem 3 from Project Euler, but I just found out that my code is really bad, it would take so much time to finish processing the code and I honestly do not know how to optimize it....
1
vote
1answer
45 views

Euler Project Problem 2 JavaScript

Just solved Euler Project Problem 2 using JavaScript and I would like to know how I could improve my code. I do think it looks good, but you never know. Problem Statement Each new term in the ...
27
votes
7answers
7k views

Trapping Rain Water

This task is taken from Leetcode - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. ...
1
vote
1answer
49 views

Minimum Window Substring in Swift exceeds LeetCode runtime check

This is a popular question on LeetCode: 76. Minimum Window Substring Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in ...
5
votes
1answer
4k views

Code Vita: Chakravyuha

Problem Statement A Chakravyuha is a wheel-like formation. Pictorially it is depicted as below A Chakravyuha has a very well-defined co-ordinate system. Each point on the co-...
1
vote
1answer
83 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 ...
4
votes
2answers
701 views

PermCheck Codility

The following code gets 100% on the PermCheck task on Codility. It should be O(N). The question is: A non-empty array A consisting of N integers is given. A permutation is a sequence ...
1
vote
1answer
86 views

Python IPv6 verifier, parser and converter

This is a simple Python 3 program that verifies whether a string is a valid IPv6 address or not, parses IPv6 address to its hexadecimal and decimal values, and converts an integer to IPv6 format. I am ...
3
votes
1answer
78 views

IOSP Kata: merge two sorted arrays without iterators

I wrote the code below as a Kata to practice the Integration Operation Segregation Principle (IOSP, clean-code-developers.com). I would like to have some feedback ...
1
vote
2answers
103 views

HackerRank "Array Manipulation" challenge (using Microsoft concurrent extensions)

I've been practising my coding skills because I have an interview coming up. The HackerRank challenge has 16 test cases; the code passes 9 of them and the other 7 time out. If you go to HackerRank ...
3
votes
3answers
1k views

Bitmasking and searching consecutive 1's

I have written code to count the continuous ones in an array or you can use binary string for convenience. Any solution using the binary string is acceptable. My Solution is: ...
11
votes
9answers
66k views

Find the repeated elements in a list

You are given an array of n+2 elements. All elements of the array are in range 1 to n. All elements occur once except two numbers, which occur twice. Your task is to find the two repeating numbers. ...
2
votes
3answers
122 views

Finds Keywords in Log Files

This is my first project in C and I wanted a more experienced person's insight on how I made the whole program. Just looking for feedback it works how I want it to. The Github is here. Thank you so ...
10
votes
3answers
3k views

Check a string for any occurrences of certain character classes

This is a warm-up programming exercise for learning string methods in Python from HackerRank: You are given a string S. Your task is to find if string ...
4
votes
1answer
89 views

Determine whether an array contains duplicate values

My solution for the leet code problem to search an array of ints for duplicate values and return a boolean seems quite efficient (< 90% of submissions runtime). However, I am currently reviewing ...

1
2 3 4 5
65