Skip to content

Only Code

Eat Code Sleep – repeat

  • Home
  • Arrays
  • Linked Lists
  • Trees
  • Stacks
  • Queues
  • Heaps
  • Graphs
  • Algorithms
    • Sorting
    • Dynamic Programming
    • Divide and Conquer
    • Backtracking & Recursion
    • Greedy approach
    • Breadth First Search (BFS)
    • Depth First Search (DFS)

Only Code

Eat Code Sleep – repeat

Close menu
  • Home
  • Arrays
  • Linked Lists
  • Trees
  • Stacks
  • Queues
  • Heaps
  • Graphs
  • Algorithms
    • Sorting
    • Dynamic Programming
    • Divide and Conquer
    • Backtracking & Recursion
    • Greedy approach
    • Breadth First Search (BFS)
    • Depth First Search (DFS)

Only Code

Eat Code Sleep – repeat

Search Toggle menu

Category: Competitive Programming

Fibonacci Numbers in O(logn) [Matrix Exponentiation]

Matrix multiplication can be performed in O(logn) by using matrix exponentiation. It is one of the most used techniques

Competitive Programming, Mathematics

Minimum number of moves to equal array elements – LeetCode Solution [Medium]

Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment n – 1 elements of the array by 1.

Competitive Programming, Mathematics

Number of ways to climb a stair having n steps – LeetCode Solution [Easy]

You are climbing a staircase. It has n steps upto the top. Each time you can either climb 1 step or 2 steps. You’ve to find the number of ways to climb the stair.

Competitive Programming, Dynamic Programming

Implementing basic Mathematical operations (Euclidean algorithm for GCD)

Given two non-negative integers a and b, you’ve to find the Greatest Common Divisor (GCD) or Highest Common Factor (HCF) of the two numbers. In other words, find the largest number that divides them both. The Euclidean algorithm is one of the oldest numerical algorithms to compute the greatest common divisor (gcd) of two positive integers.

Competitive Programming, Mathematics

Implementing basic Mathematical operations (Exponential)

Drawback of this method is that it will cause int overflow. This is because pow( ) method will calculate the exponential before taking the modulo.

Competitive Programming, Mathematics

Find all the occurrences of a substring in a given string in C++

Given a string s1, find the occurrences of string s2 in s1.
Input: s1 = “onlycode”; s2 = “code”

C/C++, Competitive Programming

Tower of Babylon Solution – SPOJ.com

Given n different types of blocks. Each one of them may be duplicated as many times as you like. Each type has a height y, a width x and a depth z.

Competitive Programming, Dynamic Programming

Stock Span Problem – LeetCode Solution [Medium]

The stock span problem is a financial problem defined as the maximum number of consecutive days (starting from today and going backward)

Competitive Programming, Stacks

Competitive Programming (Draughts) | CodeChef

This problem was asked in February challenge 2014. Around 900 people were able to solve this problem.
It’s not very intuitive for beginners. And also not very straightforward for someone not doing competitive programming.

Competitive Programming, Graphs

Sieve of Eratosthenes | HackerRank Solution

The sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to any given limit. It does so by iteratively marking numbers in the range as composite by marking the multiples of each prime as non-prime.

Competitive Programming, Mathematics

Posts navigation

< 1 … 5 6 7 >
  • Algorithms
  • Arrays
  • Backtracking & Recursion
  • Breadth First Search (BFS)
  • C/C++
  • Competitive Programming
  • Databases
  • Depth First Search (DFS)
  • Divide and Conquer
  • Dynamic Programming
  • Graphs
  • Greedy approach
  • Hashmaps
  • Heaps
  • Interview Questions
  • Java
  • Linked Lists
  • Machine Learning
  • Mathematics
  • Networking
  • Python
  • Queues
  • Sorting
  • Special Data Structures
  • Stacks
  • Trees
  • Web Development
© 2023 Only Code.