tnutty2k8
BAN USER- 0of 0 votes
AnswersGiven two strings s1, s2, write a function that returns true if s2 is a special substring s1. A special substring s2 is such that the s1 contains s2 where each character in s2 appears in sequence in s1, but there can be any characters in s1 in between the sequence.
- tnutty2k8 in United States
Example:
isSpecialSubstring('abcdefg', 'abc') => true
isSpecialSubstring('abcdefg', 'acg') => true
isSpecialSubstring('abcdefg', 'acb') => false;
The first two are abc and acg appears in 'abcdefg' in that order, although there might be multiple chars between the next character in s2.
The last one is false, because in 'acb' the character 'b' appears before the character 'c' in 'abcdefg'
Hope thats clear.| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersDesign a text based rpg.
- tnutty2k8 in United States
- Player can enter room.
- Room has 4 walls and items
- a wall can have door
- user can enter a different room if they chose a wall which has door.
- There is also a Enemy, which walks around different rooms. If present in the same room, takes away all your items
- A player has an inventory which has list of items
- a item can be food or weapon
User should be able to start a game and be given set options(in text) of what command to execute, like pick up item in current room, walk north, east, south, or west, or undo action to return to previous state.| Report Duplicate | Flag | PURGE
Data Structures - 0of 0 votes
AnswersGiven a matrix which each element can be the following:
0: not walkable
1: walkable
n: Integer > 1 and is distinct in matrix
Find the minimum number of path it takes to visit each n in ascending order starting from matrix[0][0]. Note matrix[0][0] will always be 1. Allowed moves are (up,right,down,left);
Example:input: [ [1,1,0,5] [0,1,1,4] ] Output: 5.
Starting from position (0,0) we need to visit next smallest n which is 4. Min Distance from (0,0) to (1,3) is 4.
- tnutty2k8 in United States
Starting from position (1,3) we need to visit next smallest n which is 5. Min Distance from (1,3) to (0,3) is 1.
Total Min Distance is 4 + 1 = 5
Edit:
Allowed moves are [up,right,down,left]| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven the following input:
- tnutty2k8 in United States
Array: array of integer coordinates(x,y) of length N
return a integer M that represents the maximum number of points that falls within the same line.
Example:
Array: [ [0,0], [1,1], [3, 12] ]
Output: 2# [0,0] and [1,1] falls in the same line. [3,12] falls on a different line. Thus the maximum number of points that falls on the same line is 2| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven the following inputs:
- tnutty2k8 in United States
Array: Array of positive non repetitive integers of length N.
K: Integers in range of [2,N)
Target: A Target integer
return any subset of Array with K elements that sums up to target.
Example:
Array: [1,2,3,4,5]
K: 2
T: 6
Output: [1,5]
Array: [1,2,3,4,5]
K: 3
T: 6
Output: [1,2,3]
Array: [1,2,3,4,5]
K: 4,
T: 11
Output: [1,2,3,5]| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswersGiven a tree print in level zig-zag order.
- tnutty2k8 in United StatesExample suppose we have the given tree structure: 1 2 3 4 5 6 it should print: 1 3 2 4 5 6 First level prints left to right. Then next level prints right to left. Alternating for each level. Assume the following node structure: Node { data: Integer, left: Node, right: Node, parent: Node, }
| Report Duplicate | Flag | PURGE
Algorithm - 0of 0 votes
AnswerDesign a system that supports updating table with options to discard the updates. It should have the following functions:
- create(String: rowName) #cannot be called until startTransaction has been called - delete(String: rowName) #cannot be called until startTransaction has been called - update(String: rowName) #cannot be called until startTransaction has been called - startTransaction() #start transaction operations( create/delete/update) - commitTransaction() #apply transaction to the actual Table( can be array-of-objects ) - discardTransaction() #discard any transaction applied thus far
Rough impl is acceptable as long as the design is displayed correctly.
- tnutty2k8 in United States| Report Duplicate | Flag | PURGE
Data Structures - 0of 0 votes
AnswersCompress String with character and its count.
- tnutty2k8 in United States
Example: "aaabbba" -> compress -> "a3b3a1”| Report Duplicate | Flag | PURGE
Web Developer Algorithm
@chrisK:
Wait why is it {{ rec(prod * array[i], i + 1) }} instead of {{ prod * rec(array[i], i+1 }} . Trying to think why the plus(+) and minus(-) recursion format differs from the divide and multiply.
Also as the for division and whether its useful or not, it would become more useful if the numbers can be floating point(although the function signature shows int), ex 0.1, then operations such as 2/0.1 could maximize its result.
I see lot of O(n^2) solution but I believe this can be solved in O(n) using hashmap which stores letters as keys and its index as values. I'll try to hash(el-oh-el) out the solution and edit post.
- tnutty2k8 August 01, 2017