Wayfair
  • OA
    • Karat
      • 811. Subdomain Visit Count
      • Ads Conversion Rate
      • Recommend Movie
      • Longest Common Continuous Subarray
      • Course Overlap
      • Halfway courses
      • Find one rectangle
      • Find all rectangles
      • Find Multiple Shapes
      • word wrap
      • word processor
      • Basic Calculator
      • Basic Calculator with parenthesis
      • 带变量计算器
      • Valid Matrix
      • nonogram
      • Node with 0 or 1 parents
      • 两个节点是否有公共祖先
      • 最远祖先
      • invalid Badge Records
      • 一小时内access多次
      • canSchedule
      • spareTime
      • sparse vector
      • sparse vector 实现add,dot和cos
      • userlogs earliest and latest access time
      • resource Access with in 5 min
      • Find Word Path in Grid
      • Find legal moves
      • 找能去的所有0区域
      • 最短路径找treasure
  • VO
    • Coding
      • Valid Palindrome
      • Add String
      • Coupon
    • System design
    • BQ
    • OOD
  • SD
  • LeetCode Tag
  • VO Onsite
Powered by GitBook
On this page
  1. OA
  2. Karat

sparse vector

PreviousspareTimeNextsparse vector 实现add,dot和cos

Last updated 3 years ago

设计sparse vector

sparseVector v = new sparseVector(100); //size constructor; size is 100.
    v.set(0, 1.0);
    v.set(3, 2.0);
    v.set(80,-4.5);

    System.out.println(v.get(80)); //should print -4.5
    System.out.println(v.get(50)); //should print 0.0

    try {
       System.out.println(v.get(101)); //error -- index out of range
       throw new IllegalStateException("We should not get here, an exception should have been thrown");
    } catch (IndexOutOfBoundsException t) {
       // success
    }
    System.out.println(v.toString()); //should print something like [1.0, 0.0, 0.0, 2.0, 0.0, ...]  

https://www.geeksforgeeks.org/implementing-sparse-vector-in-java/