Skip to main content

All Questions

2 votes
1 answer
69 views

Clique Connect: minimum spanning tree

Problem Statement You are given a weighted undirected graph G with N vertices, numbered 1 to N. Initially, G has no edges. You will perform M operations to add edges to G. The i-th operation (1≤i≤M) ...
user24714692's user avatar
6 votes
1 answer
329 views

Codeforces: D2. Counting Is Fun (Hard Version)

The code works okay for the following problem. Problem An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
user24714692's user avatar
4 votes
2 answers
497 views

Leetcode: Steps to Make Array Non-decreasing

I was trying out leetcode's Steps to Make Array Non-decreasing As per the challenge's description: You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i ...
ccot's user avatar
  • 341
1 vote
3 answers
113 views

Find min sum for indices to match equation

I want to reduce time complexity of my code: I have an array of integers arr say [1, 2, 3, 6, 67] I have an equation : a*x+b*y=z, I can use the array values in this ...
Learner's user avatar
  • 217
9 votes
4 answers
2k views

Leetcode : First Missing Positive

I was trying out leetcode's first missing positive. As per the challenge's description: Given an unsorted integer array nums, return the smallest missing positive integer. You must implement an ...
ccot's user avatar
  • 341
1 vote
1 answer
87 views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
peternish's user avatar
2 votes
1 answer
745 views

Traveling Salesman Problem for visiting cities

Implement TSP problem using best first algorithm (so it will be backtracking, branch-and-bound, and best-first). Since you are looking for a cycle, the start/finish city is not important. Therefore we ...
Ruiru's user avatar
  • 21
2 votes
1 answer
135 views

Find character at given index in a sorted sub strings [closed]

For a given string say dbac the possible substrings are [d,db,dba,dbac,b,ba,bac,a,ac,c]. Sort them and concatenate to a string: ...
Learner's user avatar
  • 217
4 votes
2 answers
589 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
9 votes
3 answers
2k views

Repeatedly remove a substring quickly

I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...
user avatar
2 votes
2 answers
95 views

For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m

A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
Szyszka947's user avatar
7 votes
2 answers
1k 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 ...
NFeruch - FreePalestine's user avatar
1 vote
1 answer
230 views

Find a secret word given an array of triplets? (codewars problem)

The rules for the puzzle are: Each triplet has the rules of how the letters are ordered in the secret word (each letter is followed by the next letter inside the triplet array). all the letters of ...
Jonas's user avatar
  • 131
1 vote
2 answers
364 views

USACO Training - Section 1.5 - Arithmetic Progressions [closed]

I am working on the USACO problem Arithmetic Progression. Here is their problem statement: An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+...
cold10's user avatar
  • 469
2 votes
2 answers
792 views

Subarrays with length

You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
Vaibhav Vishal Singh's user avatar

15 30 50 per page
1
2 3 4 5
17