325 questions
2
votes
1
answer
107
views
Cyclic Sort Implemenation
I was just trying to implement cyclic sort after watching the theory part of a YouTube video (https://youtu.be/JfinxytTYFQ?list=PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ&t=889).
I came up with the below ...
7
votes
1
answer
367
views
Given an array find all the elements that appear thrice except one element appearing once: how does the optimal approach using bit-manipulation work
I came across LeetCode problem 137. Single Number II:
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and ...
2
votes
1
answer
4k
views
Minimum numbers of operation required to make an array bitonic [closed]
I am trying to solve this code challenge:
Given an array arr of n integers, in a single operation, one can reduce any element of the array by 1. Find the minimum number of operations required to ...
-3
votes
1
answer
80
views
Where do I go out of bounds in this Reverse Words In a String problem?
I'm going out of bounds somewhere while iterating a very long string but I can't seem to find out where?
import java.util.*;
public class Solution {
//Helper function to reverse words in string
...
2
votes
1
answer
64
views
Efficient Algorithm for Finding the Longest Increasing Subsequence [duplicate]
I'm working on a project where I need to find the longest increasing subsequence (LIS) from a given array of integers. However, the array can be quite large, so I'm looking for an efficient algorithm ...
0
votes
0
answers
64
views
Constructing an algorithm to find the smallest log(log(n)) elements from an array of length n
I am a math student and I have been asked to help grade answer sheets for an Algorithms course as one of my professors is unwell. While I am quite familiar with combinatorial algorithms, I am not well ...
0
votes
3
answers
199
views
What is the exact time complexity of this algorithm?
I attempted to solve the problem at this HackerRank link (https://www.hackerrank.com/challenges/diagonal-difference/problem?isFullScreen=true) Given a square matrix, calculate the absolute difference ...
-1
votes
1
answer
188
views
online judge problems program c++ [closed]
#include <iostream>
using namespace std;
const int TMAX = 2000000;
int num_chupiguays(const int a[], int n) {
int suma = 0;
int resul = 0;
for (int i = 0; i < n; i++) {
...
0
votes
2
answers
81
views
Diff an array of objects so that it matches another without recreating any valid objects
Let's say I have 2 arrays each of which holds a few different objects
class Object1 {}
class Object2 {}
class Object3 {}
class Object4 {}
class Object5 {}
class Object6 {}
const arrayA = [
new ...
0
votes
1
answer
137
views
I wrote a function in C language that as I would think has O(n^3) time complexity, but as n grows, for some reason it behaves like O(n^2)
I have written a function that makes an array unique, but I don't quite understand how the time complexity works here.
Here's my whole program:
#include <stdio.h>
#include <stdlib.h>
#...
-1
votes
2
answers
82
views
Recursion method is invoked even after loop condition is met
public int removeMin(Integer[] arr, int count) {
Integer[] tempArr = new Integer[arr.length -1];
int index = 0;
for (int i = 1; i<arr.length; i++) {
tempArr[index] = arr[i] ...
1
vote
0
answers
64
views
Iteration failure in radixsort aka bucket sort algorithm,Radix sort inefficient because it assigns wrong size for bucket 0 according to the unit test
For one of my assignment, I am asked to implement a radix sort algorithm. Here is the code that was written so far:
class RadixSort:
def __init__(self):
self.base = 7
self....
0
votes
1
answer
315
views
Maximum sum of two elements
You are given two arrays each with n integers. Find the maximum sum of two elements. You have to choose one element from the first array, one element from the second array and their indexes have to be ...
0
votes
1
answer
190
views
Is the time complexity of the code snippet less than O(n^2)?
I am new to algorithms and data structures.
Thus, I joined LeetCode to improve my skills.
The first problem is to propose an algorithm whose time complexity is less than O(n^2).
I used the code ...
1
vote
1
answer
85
views
Inserting elements in a specific positions in the existing array
I have a List and Map as below,
val exampleList = List("A","B","C","D","E","A","L","M","N")
val exampleMap = ...