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

**URL:** <https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680>\
**Category:** Discussion & Solutions\
**Tags:** business\
**Created:** [October 20, 2019, 9:23am UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680 "2019-10-20T09:23:31Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Summer\_Jance](https://onehack.st/user_avatar/onehack.st/summer_jance/32/19952_2.png) [@Summer\_Jance](https://onehack.st/u/Summer_Jance)\
**Post date:** [October 27, 2019, 10:25am UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/45 "2019-10-27T10:25:25Z")

</div>

primarily can think of 2 ways to solve the above combination problem.  
using for loop and recursion.

prefer loop as i’m not sure you’re language supports tail call optimization

for i → 0 to len(str)  
comb = ithStr  
print(comb)  
&nbsp; for j → i+1 to len(str)  
&nbsp;&nbsp;&nbsp;&nbsp;comb = comb + jthStr  
&nbsp;&nbsp;&nbsp;&nbsp;print(comb)  
&nbsp;end forj  
end fori

**Note**

```auto
comb = comb + jthStr

```

in some language + can be used for combining string. Some don’t you can use you’re language specific / write a general function todo so

---

<div class="post-metadata">

**Author:** ![nikhilknick](https://onehack.st/user_avatar/onehack.st/nikhilknick/32/22060_2.png) [@nikhilknick](https://onehack.st/u/nikhilknick)\
**Post date:** [November 2, 2019, 8:40pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/65 "2019-11-02T20:40:57Z")

</div>

Solution to problem 8  
code in javascript

```
const outsub = (str) => {
  for(var i=0;i<=str.length;i++){
      for(var j=0;j<=str.length-i;j++){
            console.log(str.substr(i,j));
    }
  }
}
outsub('abcd');

```

---

<div class="post-metadata">

**Author:** ![Darklooter](https://onehack.st/user_avatar/onehack.st/darklooter/32/1882_2.png) [@Darklooter](https://onehack.st/u/Darklooter)\
**Post date:** [October 27, 2019, 11:35pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/47 "2019-10-27T23:35:49Z")

</div>

I have to learn maps , I guess any problem can b solved by this.😂😂🤪

---

<div class="post-metadata">

**Author:** ![goku\_pistol](https://onehack.st/user_avatar/onehack.st/goku_pistol/32/24327_2.png) [@goku\_pistol](https://onehack.st/u/goku_pistol)\
**Post date:** [October 28, 2019, 5:25am UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/48 "2019-10-28T05:25:18Z")

</div>

You should!! map(),filter(), reduce() and zip() are really useful.  
Btw, I have only used it for taking inputs in single line and type cast string to integer i.e. same as “cin \>\> a \>\> b \>\> c” in C++ 😅

---

<div class="post-metadata">

**Author:** ![Ak\_Malviya](https://onehack.st/user_avatar/onehack.st/ak_malviya/32/23188_2.png) [@Ak\_Malviya](https://onehack.st/u/Ak_Malviya)\
**Post date:** [October 28, 2019, 7:39am UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/49 "2019-10-28T07:39:08Z")

</div>

**Problem Number 8 Solution:**

```
#include<iostream>
#include<cstring>
#include<string.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int i=0,j=0,k=0;

    int size_str=str.length();
    while(i < size_str)
    {
        j=0;
        while(j<size_str-i)
        {
            cout<<"\t"<<str[j];
            j++;
            k=j;
            while(k<size_str-i)
            {
                cout<<"\t"<<str[k];
                k++;
            }
            cout<<"\n";
        }
        cout<<"\n";

        i++;
    }
    return 0;
}

```

---

<div class="post-metadata">

**Author:** ![Ak\_Malviya](https://onehack.st/user_avatar/onehack.st/ak_malviya/32/23188_2.png) [@Ak\_Malviya](https://onehack.st/u/Ak_Malviya)\
**Post date:** [October 28, 2019, 11:41am UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/50 "2019-10-28T11:41:10Z")

</div>

**Problem 9:**  
You are given an array of nonnegative integers. Let’s say you start at the beginning of the array and are trying to advance to the end. You can advance at most, the number of steps that you’re currently on. Determine whether you can get to the end of the array.

For example, given the array `[1, 3, 1, 2, 0, 1]` , we can go from indices `0 -> 1 -> 3 -> 5` , so return `true` .

Given the array `[1, 2, 1, 0, 0]` , we can’t reach the end, so return `false` .

---

<div class="post-metadata">

**Author:** ![Darklooter](https://onehack.st/user_avatar/onehack.st/darklooter/32/1882_2.png) [@Darklooter](https://onehack.st/u/Darklooter)\
**Post date:** [October 28, 2019, 3:13pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/54 "2019-10-28T15:13:04Z")

</div>

the statement seems a little confusing can you tell me the source of this question?

---

<div class="post-metadata">

**Author:** ![Ak\_Malviya](https://onehack.st/user_avatar/onehack.st/ak_malviya/32/23188_2.png) [@Ak\_Malviya](https://onehack.st/u/Ak_Malviya)\
**Post date:** [October 28, 2019, 3:17pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/55 "2019-10-28T15:17:30Z")

</div>

Daily Coding Problem, It is asked by **google**.

---

<div class="post-metadata">

**Author:** ![Darklooter](https://onehack.st/user_avatar/onehack.st/darklooter/32/1882_2.png) [@Darklooter](https://onehack.st/u/Darklooter)\
**Post date:** [October 28, 2019, 5:13pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/56 "2019-10-28T17:13:27Z")

</div>

Is that the exact statement ?

---

<div class="post-metadata">

**Author:** ![Ak\_Malviya](https://onehack.st/user_avatar/onehack.st/ak_malviya/32/23188_2.png) [@Ak\_Malviya](https://onehack.st/u/Ak_Malviya)\
**Post date:** [October 28, 2019, 5:25pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/57 "2019-10-28T17:25:36Z")

</div>

Yes, this is the exact statement. This problem can be solved by dynamic programming technique.

---

<div class="post-metadata">

**Author:** ![Magnus](https://onehack.st/user_avatar/onehack.st/magnus/32/26177_2.png) [@Magnus](https://onehack.st/u/Magnus)\
**Post date:** [October 29, 2019, 1:58pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/58 "2019-10-29T13:58:28Z")

</div>

I wrote a solution but I’m not 100% sure I understood the problem (bad practice I know :p)  
what I understood:  
we start from the first index, and the next index we jump to is currentindex+the value in that current index.  
we keep doing this until either:

- we get to the end
- we go out of bound
- the value we get to is zero (we can’t go forward anymore).

Based on that explanation, here is the function that does the job, in c++:

```
bool reachesEnd(int arr[] ,const int arrSize, int currentIndex){
if(currentIndex==arrSize-1) return 1;
if(currentIndex>=arrSize) return 0;
if(arr[currentIndex]==0) return 0;

return reachesEnd(arr , arrSize , currentIndex+arr[currentIndex]); }

```

Please inform me if I understood the problem correctly.

---

<div class="post-metadata">

**Author:** ![Ak\_Malviya](https://onehack.st/user_avatar/onehack.st/ak_malviya/32/23188_2.png) [@Ak\_Malviya](https://onehack.st/u/Ak_Malviya)\
**Post date:** [October 29, 2019, 5:24pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/59 "2019-10-29T17:24:03Z")

</div>

Yes, you understood the problem correctly.

---

<div class="post-metadata">

**Author:** ![Mayank](https://onehack.st/user_avatar/onehack.st/mayank/32/18032_2.png) [@Mayank](https://onehack.st/u/Mayank)\
**Post date:** [November 2, 2019, 5:04pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/61 "2019-11-02T17:04:16Z")

</div>

for Problem 9:  
Each state defines number of jumps can be made from one node to other.  
for example  
state `5` , represent jumps at max `5` and at min `0` and  
to solve you must reach the end of the node.

_Assumption_

1. All states are whole number.

_edge cases_

1. If the current node is the last node.
2. if all the nodes state are `0`.
3. if node is not end\_indx and value is `0`.

Pseudocode for **top down approach** :

```auto
func jump_resolver(arr,curr_indx)
  if curr_indx is end_indx (reached end )
     return true;
end if

 if curr_indx past end_indx (greater than end_indx)
   return false
end if

state_val = arr[curr_indx]
if state_val == 0 // no increment we stop here
  return false;

 for i=state_val to 1 do
     reached = jump_resolver(arr,curr_indx+i);
      if reached 
      return true;
 end for
return false; // as we tried all the jumps     

```

Pseudocode for **bottom up approach** :  
a. using stack iterativerly

> stack initalized with {fnstate:‘CALL’,ctxt:{indx:0}

```auto
dest = false // is end reached

while stack.hasElements()
 fnstate,ctxt= stk.pop() // here pop and get what is the current function state and context
if fnstate == 'CALL'
 
     if curr_indx past end_indx (greater than end_indx)
       dest = false
       continue; // moves to start of while
     end if

    if ctxt.indx == end_indx
        dest = true;
   
     else // inner else
       val = arr[ctxt.indx]; // fetch the value from current index of arr
               if val == 0
                  dest = false // if it's not nth index and it's value is 0 , return false
                  continue; // move forward with while loop
                end if
       push to stk {fnstate:'RES',ctxt:{indx:ctxt.indx} // later we will resume at context index

      for i = val to 1 do
        push to stk {fnstate:'CALL',ctxt:{indx:ctxt.indx+i}
        if dest // on destination reach
           break;
      end for // end inner for
end while // outer while

```

**Note**

1. There is even better way to do this via disjoint set.
2. using memoization for recursion would be better.

---

<div class="post-metadata">

**Author:** ![Mayank](https://onehack.st/user_avatar/onehack.st/mayank/32/18032_2.png) [@Mayank](https://onehack.st/u/Mayank)\
**Post date:** [November 3, 2019, 11:01pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/68 "2019-11-03T23:01:04Z")

</div>

> [@Ak\_Malviya](#):
>
> Yes, this is the exact statement. This problem can be solved by dynamic programming technique.

The problem can be solved **by recursion [for better use DP , to avoid TLE]**.

Is that what you meant?

---

<div class="post-metadata">

**Author:** ![Mahammedi\_Zakaria](https://onehack.st/user_avatar/onehack.st/mahammedi_zakaria/32/20622_2.png) [@Mahammedi\_Zakaria](https://onehack.st/u/Mahammedi_Zakaria)\
**Post date:** [October 28, 2019, 11:54am UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/52 "2019-10-28T11:54:08Z")

</div>

hello guys  
i have a quick simple question , i want to code a food app that have an integrated delivery tracking system and chat  
what am i going to need ?

---

<div class="post-metadata">

**Author:** ![Darklooter](https://onehack.st/user_avatar/onehack.st/darklooter/32/1882_2.png) [@Darklooter](https://onehack.st/u/Darklooter)\
**Post date:** [October 28, 2019, 12:37pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/53 "2019-10-28T12:37:54Z")

</div>

A computer  
Decide a tech stack  
Firebase  
(Search youtube for reference )

---

<div class="post-metadata">

**Author:** ![Darklooter](https://onehack.st/user_avatar/onehack.st/darklooter/32/1882_2.png) [@Darklooter](https://onehack.st/u/Darklooter)\
**Post date:** [October 31, 2019, 5:15pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/60 "2019-10-31T17:15:19Z")

</div>

**Problem 10**

GIven a string like  
**java is good but javascript is awesome**

sort this string on the basis of number of vowels it has. so the output will be

**is but is java good javascript awesome**

---

<div class="post-metadata">

**Author:** ![Mayank](https://onehack.st/user_avatar/onehack.st/mayank/32/18032_2.png) [@Mayank](https://onehack.st/u/Mayank)\
**Post date:** [November 2, 2019, 5:48pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/62 "2019-11-02T17:48:49Z")

</div>

theory  
fetch string , convert to array of strings  
assign each string a value based on number of vowels  
sort it and display.

pseudocode

```auto
func display()
vals[] // array of vals after split(" ")  
use treeMap (modify how elements are 
             compared , here elements are string with help of spit_vowl_count)
as you keep adding str to tree , it sorts and adds the element

for val to treeMap
   console val + ' '
end for // you can use iterator pattern if you want

end func 

func spit_vowl_count(str)
  sum = 0
  for i 0 to len(str)
  if str(i) belongs to `a` , `e`, `i`, `o`, `u`
  sum + = 1;
  end for
return sum
end func

```

---

<div class="post-metadata">

**Author:** ![nikhilknick](https://onehack.st/user_avatar/onehack.st/nikhilknick/32/22060_2.png) [@nikhilknick](https://onehack.st/u/nikhilknick)\
**Post date:** [November 2, 2019, 8:36pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/64 "2019-11-02T20:36:28Z")

</div>

My solution to Problem 10  
Code in Javascript

```
//function to count vowel of each item
const countVowels = (s)=> {
  let vowels = 'aeiouAEIOU';
  let count = 0;
  for(let i = 0; i < s.length ; i++)
if (vowels.indexOf(s[i]) !== -1)
  count += 1;
  return count;
}

//function to sort accoring to the no of vowels
const vowelSort = (str) => {
  let s = str.split(' ').sort((a,b)=>{
let countA = countVowels(a);
let countB = countVowels(b);
if (countA < countB)
return -1;
if (countA > countB)
return 1;
  })

return s.join(' '); //returning the final output
}
vowelSort('java is good but javascript is awesome');

```

---

<div class="post-metadata">

**Author:** ![nikhilknick](https://onehack.st/user_avatar/onehack.st/nikhilknick/32/22060_2.png) [@nikhilknick](https://onehack.st/u/nikhilknick)\
**Post date:** [November 2, 2019, 8:55pm UTC](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680/66 "2019-11-02T20:55:25Z")

</div>

**Problem 11**

Write a function persistence that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit.

For example:  
persistence(39) === 3 // because 3_9 = 27, 2_7 = 14, 1_4= 4 and 4 has only one digit  
persistence(999) === 4 // because 9_9_9 = 729, 7_2_9 = 126, 1_2_6 = 12, and finally 1_2 = 2  
persistence(4) === 0 // because 4 is already a one-digit number

[Previous page](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680.md?page=2)

[Next page](https://onehack.st/t/post-only-coding-problems-solutions-here-all-coding-gurus-dig-in/60680.md?page=4)
