MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / calc

Function calc

LeetCode_problems/Permutation Sequence/Solution.cpp:7–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5string s="";
6int c=0;
7void calc(int n,int k,int m,vector<int > &v){ //m always decreases by 1
8 if(m<0){
9 return ;
10 }
11
12 int d=fact[m];// factorial of m
13
14 int x=ceil(k*1.0/d*1.0);// index of the element that has to be taken from vector
15 c=c*10 + v[x-1]; // forming the number
16 s=to_string(c); // converting number to string
17 v.erase(v.begin()+x-1); // now remove that digit as permutation has every digit once
18 int next_k=k-((x-1)*d); // finding the next k which is to be further processed with the same logic
19 calc(n,next_k,m-1,v); //its a recursive function
20}
21
22
23class Solution {

Callers 1

getPermutationMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected