🌐
LeetCode
leetcode.com › discuss › interview-question › 533794 › create-k-group-using-n-members
Create k group using n members - Discuss - LeetCode
March 9, 2020 - You need to create k group using n members. The number of members in ith group should be more than or equal to the members in (i-1)th group. For example 8 members and 4 groups.
🌐
Seuhkaa
app.seuhkaa.org › 9oatf › 1rh7u.php
Group division hackerrank solution github
For this problem, we can join two tables first and then group by hacker_id and name to get total number of challenges created by each student: 1. All questions and solutions of TCS Xplore Assessment (Java) in one place. cppbetween two sets hackerrank solut HackerRank Test. programming cplusplus ...
🌐
GitHub
github.com › cstrouse › hackerrank › blob › master › division.py
hackerrank/division.py at master · cstrouse/hackerrank
from __future__ import division · · # https://www.hackerrank.com/challenges/python-division · · a = int(raw_input()) b = int(raw_input()) · print a // b ·
Author   cstrouse
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › count-the-number-of-ways-to-divide-n-in-k-groups-incrementally
Count the number of ways to divide N in k groups incrementally - GeeksforGeeks
July 12, 2025 - # Python3 implementation to count ... # Function to count the number of # ways to divide the number N def countWaystoDivide(n, k): return calculate(0, 1, n, k); # Driver Code if __name__ == '__main__': N = 8; K = 4; print(coun...
🌐
HackerRank
hackerrank.com › challenges › team-formation › problem
Team Formation | HackerRank
For the first case, Roy can form two teams: one with contestants with skill levels {-4,-3,-5} and the other one with {4,5,2,3}. The first group containing 3 members is the smallest.
Top answer
1 of 1
3

First of all, big O notation gives us an idea about the relation between two functions t(n)/i(n) when n -> infinity. To be more specific, it's an upper bound for such relation, which means it's f(n) >= t(n)/i(n). t(n) stands for the speed of growth of time spent on execution, i(n) describes the speed of growth of input. In function space (we work with functions there rather than with numbers and treat functions almost like numbers: we can divide or compare them, for example) the relation between two elements is also a function. Hence, t(n)/i(n) is a function.

Secondly, there are two methods of determining bounds for that relation.

The scientific observational approach implies the next steps. Let's see how much time it takes to execute an algorithm with 10 pieces of input. Then let's increase the input up to 100 pieces, and then up to 1000 and so on. The speed of growth of input i(n) is exponential (10^1, 10^2, 10^3, ...). Suppose, we get the exponential speed of growth of time as well (10^1 sec, 10^2 sec, 10^3 sec, ... respectively).

That means t(n)/i(n) = exp(n)/exp(n) = 1, n -> infinity (for the scientific purity sake, we can divide and compare functions only when n -> infinity, it doesn't mean anything for the practicality of the method though). We can say at least (remember it's an upper bound) the execution time of our algorithm doesn't grow faster than its input does. We might have got, say, the quadratic exponential speed of growth of time. In that case t(n)/i(n) = exp^2(n)/exp(n) = a^2n/a^n = exp(n), a > 1, n -> infinity, which means our time complexity is O(exp(n)), big O notation only reminds us that it's not a tight bound. Also, it's worth pointing out that it doesn't matter which speed of growth of input we choose. We might have wanted to increase our input linearly. Then t(n)/i(n) = exp(n)*n/n = exp(n) would express the same as t(n)/i(n) = exp^2(n)/exp(n) = a^2n/a^n = exp(n), a > 1. What matters here is the quotient.

The second approach is theoretical and mostly used in the analysis of relatively obvious cases. Say, we have a piece of code from the example:

// DP Table 
static int [][][]dp = new int[500][500][500]; 
   
// Function to count the number 
// of ways to divide the number N 
// in groups such that each group 
// has K number of elements 
static int calculate(int pos, int prev,  
                 int left, int k) 
{ 
    // Base Case 
    if (pos == k)  
    { 
        if (left == 0) 
            return 1; 
        else
            return 0; 
    } 
    
    // if N is divides completely  
    // into less than k groups 
    if (left == 0) 
        return 0; 
   
    // If the subproblem has been 
    // solved, use the value 
    if (dp[pos][prev][left] != -1) 
        return dp[pos][prev][left]; 
   
    int answer = 0; 
    
    // put all possible values  
    // greater equal to prev 
    for (int i = prev; i <= left; i++)  
    { 
        answer += calculate(pos + 1, i,  
                           left - i, k); 
    } 
   
    return dp[pos][prev][left] = answer; 
} 

// Function to count the number of  
// ways to divide the number N in groups 
static int countWaystoDivide(int n, int k) 
{ 
    // Intialize DP Table as -1 
        for (int i = 0; i < 500; i++)  
        { 
            for (int j = 0; j < 500; j++) 
            { 
                for (int l = 0; l < 500; l++) 
                    dp[i][j][l] = -1; 
            } 
        } 
   
    return calculate(0, 1, n, k); 
} 

The first thing to notice here is a 3-d array dp. It gives us a hint of the time complexity of a DP algorithm because usually, we traverse it once. Then we are concerned about the size of the array. It's initialized with the size 500*500*500 which doesn't give us a lot because 500 is a number, not a function, and it doesn't depend on the input variables, strictly speaking. It's done for the sake of simplicity though. Effectively, the dp has size of k*n*n with assumption that k <= 500 and n <= 500.

Let's prove it. Method static int calculate(int pos, int prev, int left, int k) has three actual variables pos, prev and left when k remains constant. The range of pos is 0 to k because it starts from 0 here return calculate(0, 1, n, k); and the base case is if (pos == k), the range of prev is 1 to left because it starts from 1 and iterates through up to left here for (int i = prev; i <= left; i++) and finally the range of left is n to 0 because it starts from n here return calculate(0, 1, n, k); and iterates through down to 0 here for (int i = prev; i <= left; i++). To recap, the number of possible combinations of pos, prev and left is simply their product k*n*n.

The second thing is to prove that each range of pos, prev and left is traversed only once. From the code, it can be determined by analysing this block:

for (int i = prev; i <= left; i++)  
{ 
    answer += calculate(pos + 1, i,  
                       left - i, k); 
}

All the 3 variables get changed only here. pos grows from 0 by adding 1 on each step. On each particular value of pos, prev gets changed by adding 1 from prev up to left, on each particular combination of values of pos and prev, left gets changed by subtracting i, which has the range prev to left, from left.

The idea behind this approach is once we iterate over an input variable by some rule, we get corresponding time complexity. We could iterate over a variable stepping on elements by decreasing the range by twice on each step, for example. In that case, we would get logarithmical complexity. Or we could step on every element of the input, then we would get linear complexity.

In other words, we without any doubts assume the minimum time complexity t(n)/i(n) = 1 for every algorithm from common sense. Meaning that t(n) and i(n) grow equally fast. That also means we do nothing with the input. Once we do something with the input, t(n) becomes f(n) times bigger than i(n). By the logic shown in the previous lines, we need to estimate f(n).

🌐
HackerRank
hackerrank.com › challenges › python-division › forum
Python: Division Discussions | Python | HackerRank
Please Login in order to post a comment · if name == 'main': a = int(input()) b = int(input()) print((a//b)) print((a/b))
Find elsewhere
🌐
LeetCode
leetcode.com › problems › possible-bipartition
Possible Bipartition - LeetCode
Can you solve this real interview question? Possible Bipartition - We want to split a group of n people (labeled from 1 to n) into two groups of any size. Each person may dislike some other people, and they should not go into the same group. Given the integer n and the array dislikes where dislikes[i] = [ai, bi] indicates that the person labeled ai does not like the person labeled bi, return true if it is possible to split everyone into two groups in this way.
🌐
GitHub
github.com › cassiopagnoncelli › hacker-rank-solutions › blob › master › python-division.py
hacker-rank-solutions/python-division.py at master · cassiopagnoncelli/hacker-rank-solutions
May 26, 2024 - Solutions to hackerrank.com programming challenges. - hacker-rank-solutions/python-division.py at master · cassiopagnoncelli/hacker-rank-solutions
Author   cassiopagnoncelli
🌐
LeetCode
leetcode.com › problems › counting-bits › discuss › 657019 › c-easy-solution-group-division
C++ | Easy Solution | Group Division - Counting Bits
May 28, 2020 - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
🌐
Blogger
allhackerranksolutions.blogspot.com › 2016 › 07 › python-division-hacker-rank-solution.html
Python: Division - Hacker Rank Solution - Hacker Rank Solutions
July 21, 2016 - Task Read two integers and print two lines. The first line should contain integer division, // .
🌐
GitHub
gist.github.com › meet100ni › 5dd3525792b66e91ea9c1f43c79f68e4
Python: Division HackerRank Solution · GitHub
Python: Division HackerRank Solution . GitHub Gist: instantly share code, notes, and snippets.
🌐
AlgoMonster
algo.monster › liteproblems › 1282
1282. Group the People Given the Group Size They Belong To - In-Depth Explanation
In-depth solution and explanation for LeetCode 1282. Group the People Given the Group Size They Belong To in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
GitHub
github.com › srgnk › HackerRank
GitHub - srgnk/HackerRank: Solutions to HackerRank problems · GitHub
Solutions to HackerRank problems. Contribute to srgnk/HackerRank development by creating an account on GitHub.
Starred by 457 users
Forked by 223 users
Languages   Python 85.2% | C 7.8% | C++ 5.4% | Shell 1.6%
🌐
Blogger
codeworld19.blogspot.com › home › hackerrank › hackerrank python
Python: Division - Hacker Rank Solution - CodeWorld19
April 9, 2021 - The first line should contain integer division, a//b . The second line should contain float division, a/b. You don't need to perform any rounding or formatting operations. The first line contains the first integer, a. The second line contains ...
🌐
LeetCode
leetcode.com › problems › divide-nodes-into-the-maximum-number-of-groups
Divide Nodes Into the Maximum Number of Groups - LeetCode
Divide Nodes Into the Maximum Number of Groups - You are given a positive integer n representing the number of nodes in an undirected graph. The nodes are labeled from 1 to n. You are also given a 2D integer array edges, where edges[i] = [ai, bi] ...
🌐
LeetCode
leetcode.com › problems › divide-a-string-into-groups-of-size-k
Divide a String Into Groups of Size k - LeetCode
Divide a String Into Groups of Size k - A string s can be partitioned into groups of size k using the following procedure: * The first group consists of the first k characters of the string, the second group consists of the next k characters of the ...