We are given a undirected tree with N (1 to N) nodes rooted at node 1. Every node has a value assigned with it, represented by array – A[i] where i:[1:N]. We need to answer Q queries of type : -> V X : longest length of the common prefix between value V and any ancestor of node X including
Tag: c++
Put sin on segment in 3d
i need to put a sin function, or any other function on start of segment in 3d space. Something like that: Example But in 3d space, help me pls, i spent about 4 days for solving it, but did not get result There are 2 points in space at arbitrary positions. I need a sinusoid between these two arbitrary points.
Prime numbers – I need clarification on code implementation
This is the code I know: But is this ok if you’re looking for prime numbers: Output: And also is there much difference in time complexity? Answer Your code is incorrect. This code only works because you are taking the value of n as 30, for a greater number like 1000 this will produce an incorrect result. List arr =
ByteArrayOutputStream or Binary Writer equivalent in Swift
I wondering equivalent of Java java.io.ByteArrayOutputStream or C#’s BinaryWriter into Swift. Having some difficulties in the following static public class CustomArrayOutputStream extends java.io.ByteArrayOutputStream part. I wonder how to achieve the same functionalities in the Swift. Swift Code Java Code: or equivalent of C# BinaryWriter in Swift Update: The first case is to achieve something similar but OutputStream does not have
How to call setProcessMitigationPolicy using JNA
I’m trying to convert this piece of C++ code into Java code via JNA: I already have the function SetProcessMitigationPolicy from Kernel32.dll and I’m able to call it, but how to pass such parameters? Can you please provide an example of it? UPDATE: I have tried the following code, but it is still not working. Is the function declaration correct?
How to do unsigned integer left shift bit operation in Java 1.8 that matches C#?
I’m trying to port some code from C# to Java and I’m stuck on some low-level bit operations. Here is an example snippet that I’m trying to figure out how to translate from C# to Java: Result: So far so good. How do you convert this same thing to Java? So in Java, I naively just tried turning all the
Java Iterator in C++
I am a Java user and I am getting into C++ and in Java it allows classes to reveal Iterable types so clients can traverse some instance’s collection of data. Is there any way to obtain this …
JPA Criteria builder for dynamic query
I have to write a method where I pass it some arguments and depending on which arguments are empty it modifies the query I need to execute at the end. E.g. if I want to select from a table Customer that has an ID, name, surname and address the starting query would be SELECT * FROM Customer WHERE ID=myId AND
using in C# vs. import in Java
I am coming from Java and C++ background. However, I am doing a C# application at the moment and one thing made me confused. In Java when I import a package, it means I can access the classes that are placed in that package. For example, here I imported the ArrayList class from package java.util. Recently I had a problem
Linked List – remove duplicates algorithm in C#/Java
I am studying Data Structures and Algorithms in C#/Java. After encountering a solution to the problem of Linked List duplicate removal, I have been struggling to understand it. The solution is the one …