Algorithms

Can you create two distinct arrays, each with 10 unique elements?

Design Verification Engineer

Meta

Adobe

Akamai

IBM

Lockheed Martin

NVIDIA

Did you come across this question in an interview?

Answers

Anonymous

6 months ago
4.6Exceptional
class abc;
rand int a[10];
rand int b[10];
constraint c1{foreach(a[i])  a[i] inside{[1:100]};
                      unique{a[i]}; }
constraint c2{foreach(b[i])  b[i] inside{[1:100]};
                      b[i]!=a[i];}
function void post_randomize();
$display("a=%d, b=%d", a, b);
endfunction
endclass
module tb;
abc num=new();
initial begin
num.randomize();
end
endmodule

Anonymous

9 months ago
4.2Exceptional
constraint c {
a.size == 10;
b.size == 10;
unique {a,b};
}

Unique key word makes sure that both a and b have unique elements wrt each other as well. If we want to have some elements common in both a and b, we can put unique in different unique statements. Repetition is not guaranteed, but possible.
  • Can you create two distinct arrays, each with 10 unique elements?
  • How would you go about generating two separate arrays, both 10 elements long, with no overlap?
  • Could you demonstrate creating two unique arrays, each containing 10 different elements?
  • In what way can you produce two non-overlapping arrays, each with a length of 10?
  • Please describe a method to construct two arrays, each 10 items long, ensuring all elements are distinct.
  • What approach would you take to form two individual arrays, each holding 10 unique elements?
  • How can you develop two arrays of 10 elements, ensuring uniqueness in both?
  • What is your strategy for generating two arrays, each with 10 unique elements, with no duplicates across both?
  • Could you illustrate the process of creating two unique 10-element arrays with no shared elements?
  • How would you effectively create two distinct arrays, each containing 10 elements, ensuring no repetition?
  • Generate two arrays of length 10, whose elements are unique to each?

Interview question asked to Design Verification Engineers interviewing at Northrop Grumman, Meta, Fujitsu and others: Can you create two distinct arrays, each with 10 unique elements?.