Post Only Coding Problems & Solutions Here | All Coding Guru's Dig In

for problem 11
pseudocode:

func multiplicative_peristence(num)
  count = 0
  while num > 9
    count = count + 1
    num = multOfNumber(num)
  end while
return count;
end func

func multOfNumber(num)
  mul = 1
  while num != 0
     mul *= num%10
     num =  num / 10  (removing decimal )
   end while
return mul;
end func
1 Like

Problem 12
level : Easy
Expected soln :
time complexity: log(a)
space complexity: O(1)

Given two integers dividend and divisor , divide two integers without using multiplication, division and mod operator.

Return the quotient after dividing dividend by divisor .

The integer division should truncate toward zero.

Example 1:

Input: dividend = 10, divisor = 3 Output: 3

Example 2:

Input: dividend = 7, divisor = -3 Output: -2

Note:

  • Both dividend and divisor will be 32-bit signed integers.
  • The divisor will never be 0.
  • Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 231 − 1 when the division result overflows.

problem 13:
via pattern matching
\d+ for integer
\d+\.\d+ for float
rest is string
what does something else mean?

Hello world…
What would be your thought process on this problem

let say

input A = [3]
output = [FALSE]

input A = [3,3]
output = [FALSE, TRUE]

input A = [1,2,1]
output =[FALSE, FALSE, TRUE]

input A = [1,2,3]
output = [FALSE, FALSE, FALSE ]

input A = [1,1,1]
output = [FALSE, TRUE, TRUE]

input A = [1,2,3,4,1,3,4,5]
output [FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, FALSE]

input A = [3,2,6,3,7]
output [FALSE, FALSE, FALSE , TRUE, FALSE]

it just check duplicates of element and return logical vector

Code in javascript

    const duplicateTrue = (arr) =>{
    let final = [];                  
    for(let i =0;i<arr.length;i++){
     let s = arr.slice(0,i);          
      if(s.includes(arr[i]))
      final.push(true);
    else
        final.push(false);
      }
    return final;
    }
1 Like

problem 14:
using hashtable
and having
space complexity of O(n) + O(n) for space and
time complexity O(n) .

Problem 15:
Print the pattern without using loops:

input: 12,4:
output:
12, 8 , 4 , 0, 4, 8,12

input: 10,3:
output:
10 7 4 1 -2 1 4 7 10

#include<iostream>
#include<stdlib.h>
using namespace std;
void chck(int a,int b);
void chck_nxt(int a,int b);
int x,y;
int main()
{
    cout<<"Enter Value of x";
    cin>>x;
    cout<<"Enter Value of y";
    cin>>y;
    cout<<"\n"<<x;
    chck(x,y);

}

void chck(int a,int b)
{
    int t1= a-b;
    cout<<"\n"<<t1;
    if(t1<=0)
    {
        chck_nxt(t1,b);
    }
    else
    {
        chck(t1,b);
    }
}
void chck_nxt(int a,int b)
{
    int t2 =a +b;
cout<<"\n"<<t2;
    if(t2==x)
    {

    }
    else
    {
        chck_nxt(t2,b);
    }
}

This will help you to solve your problem.

wont it lead to stackoverflow for large value of A and small value of B?
for the input A,B on the first line.

I haven’t used any stack. Then, how it will lead to stack overflow?
Please explain.

From GeeksForGeeks
How memory is allocated to different function calls in recursion?
When any function is called from main(), the memory is allocated to it on the stack. A recursive function calls itself, the memory for a called function is allocated on top of memory allocated to calling function and different copy of local variables is created for each function call. When the base case is reached, the function returns its value to the function by whom it is called and memory is de-allocated and the process continues.

Thats one of the reason where its better for bottom up approach.
PS could have PM’d but lot of folks don’t have a clue how recursion works. Sorry Modz

Reference
https://www.geeksforgeeks.org/recursion/

Thank you for letting me know how recursion works.

#include <stdio.h>

void pattern(int num, int diff) {

    if (num <= 0) {
        printf(" %d ", num);
        return;
    }
    else {
        printf("%d ", num);
        pattern(num - diff, diff);
        printf(" %d", num);
    }
}

int main(void) {
    pattern(12, 4);
    printf("\n");
    pattern(10, 3);
    return 0;
}

you are not using recursion to its fullest !

Need to solve this with JAVA.

anagrams:

input data:
act
cat
tree
race
care
acre
bee

the output should be:
act cat
acre care race

Please Give this Problem, 16 number.

Can anyone assist me in completing a cryptography code . Which should have a client and server?

Can anyone share a sample resources to learn hashtables , hashmaps like youtube link or sample problems. I am having a hard time understanding it I get the concept of key value but I’m having hard time implementing it in my solutions or using it.

Ps, do not share any link here. Pls PM me.

@Aina After some days this thread will become huge and we can’t even scroll down.
Can you please make this as page by page . So that we can navigate in between easily.

1 Like

This Theme/Script does not support Pages numbering, and when it reaches to it’s posting count I will transfer it to a new thread. And you can check/surf this thread by date numbering, Scroll-down a Bit, see at the Right side ‘‘Scroll panel’’ Move your mouse pointer on it, you will see the lite-blue scroll bar, hold and move up or down, according to dates, or just click anywhere on the scroll panel you will see how does it work. See below!

123

2 Likes