Efficient algorithm to print count and possible string outcomes of a given input string

Write an Efficient algorithm to print count and possible string outcomes of a given input string by retaining order and considering all characters during this process
Problem: given a input string as "0000" and following input scheme for the zeroes, print the possible outcomes by retaining order of the characters. input scheme: a "0" b "00" c "000" d "0000" example: "aaaa" is one string outcome and bb is another string outcome

Questions by taru22

Showing Answers 1 - 1 of 1 Answers

cfphpflex@gmail.com

  • Mar 21st, 2013
 

1. get string length
2. print length
3. for string 0000, its easy:
4. look at 0000 and quickly understand that each 0 in the string can only have 3 other possible 0 s to compare against and get a different string
5. Since changing the zeroes to any position does not yield a different string, the answer is 1
6. Code: for 0000 a bubble sort (inefficient) but gets the job done
see my code for bubble sort on GitHub https://github.com/cfphpflex/eztest2/blob/master/NimbleFish_Interview_BubbleSort_Problem_Solution.as

Code
  1.  ActionScript code:

  2.  

  3.  

  4.  

  5.  

  6.                 // function to swap values in array    

  7. // set temp for a position 1

  8.                                 arr[a]                   = arr[b];                      // reset value  on position 2

  9. // reset value on position 1

  10. // return array

  11.                         }

  12.  

  13.  

  14.                 // bubbleSwuap  function  to process array per problem logic   

  15. // arrayLen minus 1 because we determined  number of passess is len - 1, final pass is not necessary, by pass meaning loop additionally, if the sorted

  16. // arrayLen minus 1 because aray starts with 0 element position

  17. // set  second element position

  18. // if the element being swaped forward is greater than the next element position to the right, move it to the right by calling swap funciton

  19.                                                 {  

  20.                                                         arr = swap( a, b, arr );  //call swap function

  21. // break;  //  break loop  interferes with sorting larger seed arrays

  22. // return array

  23.                                 //mx.controls.Alert.show(" Pass "+ i + "Final Bubble Sorted Array:     " +  arr );

  24. //  initial array

  25. //  for array DESCENDING  sort

  26. // set aray length

  27. //  declare final Array variable calling bubbleSwap function and passing array and len arguments into it for copy

  28. "Final Bubble Sorted Array "   ;  // make a message

  29. // display alert message

  30.  

  31.                                 //var message2:String =  "Final Bubble Sorted Array "   ;  // make a message

  32.  

  33.                                 //arr2.sort(Array.DESCENDING | Array.CASEINSENSITIVE); // does not work

  34.  

  35.                                 //alertShow( message2, arr2 );   // display alert message

  36.  

  37.  

  38.                 }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions