We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Array and simple queries
Array and simple queries
Sort by
recency
|
98 Discussions
|
Please Login in order to post a comment
7 test case doesnt pass due to time limit exceeded
can anybody help in optimizing the below code in javascript? Some test cases are getting timed out.
input = input.split('\n'); let queriesArr = input.splice(2,input.length - 2); let inputArr = input[1].split(' '); let tempArr = []; queriesArr.forEach((element)=>{ let queryType = element.split(' ')[0]; let i = parseInt(element.split(' ')[1]); let j = parseInt(element.split(' ')[2]); tempArr = inputArr.splice(i-1,j-i+1); if(queryType === '1') { inputArr = [...tempArr,...inputArr]; } if(queryType === '2') { inputArr = [...inputArr,...tempArr]; } })
let absoluteValue = Math.abs(inputArr[0] - inputArr[inputArr.length - 1]); let allElements = inputArr.join(" "); console.log(absoluteValue + "\n" + allElements);
c++ style:
I have a question First I wrote this code which times out
c solution...
include
include
include
include
include
// Treap without rotating operations struct Node { struct Node *left, *right; int data; int pri; // priority of this Treap Node int size; // Order Statistic Tree, used for relocating elements }; typedef struct Node Node;
inline Node* new_Node(int v) { Node* node = (Node*) malloc(sizeof(Node)); node->left = node->right = NULL; node->data = v; node->pri = rand(); node->size = 1; return node; }
inline int Node_get_size(Node* node) { if (node) return node->size; return 0; }
// Merge lt & rt, lt must be on the left-side of rt Node* merge(Node* lt, Node* rt) { if (lt == NULL && rt == NULL) return NULL;
}
// split k nodes to the returned tree from *ref_tree // *ref_tree will be modified during splitting // as a result, splitted_tree will have k nodes // and ref_tree will have (n-k) nodes Node split(Node** ref_tree, int k) { Node* tree = *ref_tree;
}
// print the inorder traversal of the Treap void print_inorder(Node* root) { if (!root) return; print_inorder(root->left); printf("%d ", root->data); print_inorder(root->right); }
int main() { srand(clock());
}