LeetCode - Algorithms - 342. Power of Four

Problem

342. Power of Four

Java

1

1
2
3
4
5
6
7
class Solution {
public boolean isPowerOfFour(int num) {
for (; num > 0 && num % 4 == 0; )
num = num >>> 2;
return num == 1;
}
}

Submission Detail

  • 1060 / 1060 test cases passed.
  • Runtime: 1 ms, faster than 100.00% of Java online submissions for Power of Four.
  • Memory Usage: 37 MB, less than 34.15% of Java online submissions for Power of Four.

Logarithm

1
2
3
4
5
6
7
8
class Solution {
public boolean isPowerOfFour(int num) {
if (num < 1)
return false;
Double logbase4 = Math.log(num) / Math.log(4);
return logbase4 - logbase4.intValue() <= 0.00000000000001;
}
}

Submission Detail

  • 1060 / 1060 test cases passed.
  • Runtime: 1 ms, faster than 100.00% of Java online submissions for Power of Four.
  • Memory Usage: 36.9 MB, less than 45.20% of Java online submissions for Power of Four.

bit magic 1

Check if given number is power of 4 or not

1
2
3
4
5
class Solution {
public boolean isPowerOfFour(int num) {
return num != 0 && (num & (num - 1)) == 0 && (num & 0xAAAAAAAA) == 0;
}
}

Submission Detail

  • 1060 / 1060 test cases passed.
  • Runtime: 2 ms, faster than 28.69% of Java online submissions for Power of Four.
  • Memory Usage: 38.6 MB, less than 13.38% of Java online submissions for Power of Four.

bit magic 2

Check if given number is power of 4 or not

1
2
3
4
5
class Solution {
public boolean isPowerOfFour(int num) {
return ((num & (num - 1)) == 0) && (num % 3 == 1);
}
}

Submission Detail

  • 1060 / 1060 test cases passed.
  • Runtime: 1 ms, faster than 100.00% of Java online submissions for Power of Four.
  • Memory Usage: 38.8 MB, less than 8.34% of Java online submissions for Power of Four.

LeetCode - Algorithms - 231. Power of Two

Problem

231. Power of Two

Java

1

1
2
3
4
5
6
7
class Solution {
public boolean isPowerOfTwo(int n) {
for (; n > 0 && (n & 1) == 0; )
n = n >>> 1;
return n == 1;
}
}

Submission Detail

  • 1108 / 1108 test cases passed.
  • Runtime: 1 ms, faster than 100.00% of Java online submissions for Power of Two.
  • Memory Usage: 36.8 MB, less than 52.24% of Java online submissions for Power of Two.

binary logarithm

1
2
3
4
5
6
7
8
class Solution {
public boolean isPowerOfTwo(int n) {
if (n < 1)
return false;
Double logbase2 = Math.log(n) / Math.log(2);
return logbase2 - logbase2.intValue() <= 0.00000000000001;
}
}

Submission Detail

  • 1108 / 1108 test cases passed.
  • Runtime: 2 ms, faster than 38.56% of Java online submissions for Power of Two.
  • Memory Usage: 38.7 MB, less than 6.14% of Java online submissions for Power of Two.

bit magic

© java bit magic

1
2
3
4
5
6
7
class Solution {
public boolean isPowerOfTwo(int n) {
if (n < 1)
return false;
return (n & (n - 1)) == 0;
}
}

Submission Detail

  • 1108 / 1108 test cases passed.
  • Runtime: 1 ms, faster than 100.00% of Java online submissions for Power of Two.
  • Memory Usage: 38.5 MB, less than 11.61% of Java online submissions for Power of Two.

LeetCode - Algorithms - 476. Number Complement

Problem

476. Number Complement This question is the same as 1009

Java

naive

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public int findComplement(int num) {
int r = 0;
String s = Integer.toBinaryString(num);
final int N = s.length();
char[] a = new char[N];
for (int i = 0; i < N; i++) {
a[i] = s.charAt(i) == '0' ? '1' : '0';
}
r = Integer.parseInt(String.valueOf(a),2);
return r;
}
}

Submission Detail

  • 149 / 149 test cases passed.
  • Runtime: 1 ms, faster than 35.06% of Java online submissions for Number Complement.
  • Memory Usage: 38.5 MB, less than 5.05% of Java online submissions for Number Complement.

2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public int findComplement(int num) {
String s = Integer.toBinaryString(num);
int r = 0;
final int N = s.length();
char[] a = s.toCharArray();
if (a[N - 1] == '0')
r = 1;
for (int i = N - 2; i >= 0; i--) {
if (a[i] == '0')
r += 2 << (N - 2 - i);
}
return r;
}
}

Submission Detail

  • 149 / 149 test cases passed.
  • Runtime: 1 ms, faster than 35.06% of Java online submissions for Number Complement.
  • Memory Usage: 37.7 MB, less than 18.78% of Java online submissions for Number Complement.

3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int findComplement(int num) {
String s = Integer.toBinaryString(num);
int r = 0;
final int N = s.length();
if (s.charAt(N - 1) == '0')
r = 1;
for (int i = N - 2; i >= 0; i--) {
if (s.charAt(i) == '0')
r += 2 << (N - 2 - i);
}
return r;
}
}

Submission Detail

  • 149 / 149 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Number Complement.
  • Memory Usage: 36.4 MB, less than 49.07% of Java online submissions for Number Complement.

4

1009. Complement of Base 10 Integer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int bitwiseComplement(int N) {
String s = Integer.toBinaryString(N);
int r = 0;
final int LEN = s.length();
if (s.charAt(LEN - 1) == '0')
r = 1;
for (int i = LEN - 2; i >= 0; i--) {
if (s.charAt(i) == '0')
r += 2 << (LEN - 2 - i);
}
return r;
}
}

Submission Detail

  • 128 / 128 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Complement of Base 10 Integer.
  • Memory Usage: 36.5 MB, less than 29.82% of Java online submissions for Complement of Base 10 Integer.

LeetCode - Algorithms - 66. Plus One

Problem

66. Plus One

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Solution {
public int[] plusOne(int[] digits) {
final int N = digits.length;
List<Integer> list = new ArrayList<Integer>();
boolean carry = false;
int tmp = digits[N - 1] + 1;
if (tmp < 10) {
list.add(tmp);
} else {
list.add(tmp % 10);
carry = true;
}
if (N >= 2) {
for (int i = N - 2; i >= 0; i--) {
tmp = digits[i];
if (carry)
tmp++;
if (tmp < 10) {
carry = false;
list.add(tmp);
} else {
carry = true;
list.add(tmp % 10);
}
}
}
if (carry)
list.add(1);

final int LEN = list.size();
int[] a = new int[LEN];
for (int i = 0; i < LEN; i++) {
a[LEN - i - 1] = list.get(i).intValue();
}
return a;
}
}

Submission Detail

  • 109 / 109 test cases passed.
  • Runtime: 1 ms, faster than 17.94% of Java online submissions for Plus One.
  • Memory Usage: 39.9 MB, less than 5.08% of Java online submissions for Plus One.

2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public int[] plusOne(int[] digits) {
final int N = digits.length;
List<Integer> list = new ArrayList<Integer>();
boolean carry = false;
int tmp = digits[N - 1] + 1;
if (tmp < 10) {
list.add(tmp);
} else {
list.add(tmp - 10);
carry = true;
}
for (int i = N - 2; i >= 0; i--) {
tmp = digits[i];
if (carry)
tmp++;
if (tmp < 10) {
carry = false;
list.add(tmp);
} else {
carry = true;
list.add(tmp - 10);
}
}
if (carry)
list.add(1);

final int LEN = list.size();
int[] a = new int[LEN];
for (int i = 0; i < LEN; i++) {
a[LEN - i - 1] = list.get(i).intValue();
}
return a;
}
}

Submission Detail

  • 109 / 109 test cases passed.
  • Runtime: 1 ms, faster than 17.94% of Java online submissions for Plus One.
  • Memory Usage: 38.4 MB, less than 20.96% of Java online submissions for Plus One.

3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution {
public int[] plusOne(int[] digits) {
final int N = digits.length;
int[] a2 = new int[N];
boolean carry = false;
int tmp = digits[N - 1] + 1;
if (tmp < 10) {
a2[N - 1] = (tmp);
} else {
a2[N - 1] = tmp - 10;
carry = true;
}
for (int i = N - 2; i >= 0; i--) {
tmp = digits[i];
if (carry)
tmp++;
if (tmp < 10) {
carry = false;
a2[i] = tmp;
} else {
carry = true;
a2[i] = tmp - 10;
}
}
if (carry) {
int[] a1 = new int[N + 1];
a1[0] = 1;
System.arraycopy(a2, 0, a1, 1, N);
return a1;
} else
return a2;
}
}

Submission Detail

  • 109 / 109 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Plus One.
  • Memory Usage: 39.6 MB, less than 8.37% of Java online submissions for Plus One.

LeetCode - Algorithms - 1486. XOR Operation in an Array

Problem

1486. XOR Operation in an Array

Java

1
2
3
4
5
6
7
8
9
10
class Solution {
public int xorOperation(int n, int start) {
int r = start;
for (; n > 1; n--) {
start += 2;
r = r ^ start;
}
return r;
}
}

Submission Detail

  • 54 / 54 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for XOR Operation in an Array.
  • Memory Usage: 38.3 MB, less than 100.00% of Java online submissions for XOR Operation in an Array.

LeetCode - Algorithms - 1480. Running Sum of 1d Array

Problem

1480. Running Sum of 1d Array

Java

1

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public int[] runningSum(int[] nums) {
int[] a = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j <= i; j++) {
a[i] += nums[j];
}
}
return a;
}
}

Submission Detail

  • 53 / 53 test cases passed.
  • Runtime: 5 ms, faster than 5.83% of Java online submissions for Running Sum of 1d Array.
  • Memory Usage: 41.2 MB, less than 50.00% of Java online submissions for Running Sum of 1d Array.

2

1
2
3
4
5
6
7
8
9
10
class Solution {
public int[] runningSum(int[] nums) {
int[] a = new int[nums.length];
a[0] = nums[0];
for (int i = 1; i < nums.length; i++) {
a[i] = a[i - 1] + nums[i];
}
return a;
}
}

Submission Detail

  • 53 / 53 test cases passed.
  • Runtime: 1 ms, faster than 10.26% of Java online submissions for Running Sum of 1d Array.
  • Memory Usage: 40.7 MB, less than 50.00% of Java online submissions for Running Sum of 1d Array.

3

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public int[] runningSum(int[] nums) {
final int N = nums.length;
int[] a = new int[N];
a[0] = nums[0];
for (int i = 1; i < N; i++) {
a[i] = a[i - 1] + nums[i];
}
return a;
}
}

Submission Detail

  • 53 / 53 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Running Sum of 1d Array.
  • Memory Usage: 40.6 MB, less than 50.00% of Java online submissions for Running Sum of 1d Array.

LeetCode - Algorithms - 1342. Number of Steps to Reduce a Number to Zero

Problem

1342. Number of Steps to Reduce a Number to Zero

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int numberOfSteps (int num) {
int i = 0;
while (num > 0) {
if ((num & 1) == 1) {
num--;
} else {
num = num >> 1;
}
i++;
}
return i;
}
}

Submission Detail

  • 204 / 204 test cases passed.
  • Runtime: 1 ms, faster than 19.49% of Java online submissions for Number of Steps to Reduce a Number to Zero.
  • Memory Usage: 38 MB, less than 11.94% of Java online submissions for Number of Steps to Reduce a Number to Zero.

2

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution {
public int numberOfSteps (int num) {
int i = 0;
for (; num > 0; i++) {
if ((num & 1) == 1) {
num--;
} else {
num = num >> 1;
}
}
return i;
}
}

Submission Detail

  • 204 / 204 test cases passed.
  • Runtime: 0 ms, faster than 100.00% of Java online submissions for Number of Steps to Reduce a Number to Zero.
  • Memory Usage: 38.2 MB, less than 6.92% of Java online submissions for Number of Steps to Reduce a Number to Zero.

United States Declaration of Independence

1823 facsimile of the engrossed copy

In CONGRESS, July 4, 1776.
The unanimous Declaration of the thirteen united States of America,

When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature’s God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.

We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.–That to secure these rights, Governments are instituted among Men, deriving their just powers from the consent of the governed,–That whenever any Form of Government becomes destructive of these ends, it is the Right of the People to alter or to abolish it, and to institute new Government, laying its foundation on such principles and organizing its powers in such form, as to them shall seem most likely to effect their Safety and Happiness. Prudence, indeed, will dictate that Governments long established should not be changed for light and transient causes; and accordingly all experience hath shewn, that mankind are more disposed to suffer, while evils are sufferable, than to right themselves by abolishing the forms to which they are accustomed. But when a long train of abuses and usurpations, pursuing invariably the same Object evinces a design to reduce them under absolute Despotism, it is their right, it is their duty, to throw off such Government, and to provide new Guards for their future security.

Such has been the patient sufferance of these Colonies; and such is now the necessity which constrains them to alter their former Systems of Government. The history of the present King of Great Britain is a history of repeated injuries and usurpations, all having in direct object the establishment of an absolute Tyranny over these States. To prove this, let Facts be submitted to a candid world.

He has refused his Assent to Laws, the most wholesome and necessary for the public good.

He has forbidden his Governors to pass Laws of immediate and pressing importance, unless suspended in their operation till his Assent should be obtained; and when so suspended, he has utterly neglected to attend to them.

He has refused to pass other Laws for the accommodation of large districts of people, unless those people would relinquish the right of Representation in the Legislature, a right inestimable to them and formidable to tyrants only.

He has called together legislative bodies at places unusual, uncomfortable, and distant from the depository of their Public Records, for the sole purpose of fatiguing them into compliance with his measures.

He has dissolved Representative Houses repeatedly, for opposing with manly firmness of his invasions on the rights of the people.

He has refused for a long time, after such dissolutions, to cause others to be elected, whereby the Legislative Powers, incapable of Annihilation, have returned to the People at large for their exercise; the State remaining in the meantime exposed to all the dangers of invasion from without, and convulsions within.

He has endeavoured to prevent the population of these States; for that purpose obstructing the Laws for Naturalization of Foreigners; refusing to pass others to encourage their migrations hither, and raising the conditions of new Appropriations of Lands.

He has obstructed the Administration of Justice by refusing his Assent to Laws for establishing Judiciary Powers.

He has made Judges dependent on his Will alone for the tenure of their offices, and the amount and payment of their salaries.

He has erected a multitude of New Offices, and sent hither swarms of Officers to harass our people and eat out their substance.

He has kept among us, in times of peace, Standing Armies without the Consent of our legislatures.

He has affected to render the Military independent of and superior to the Civil Power.

He has combined with others to subject us to a jurisdiction foreign to our constitution, and unacknowledged by our laws; giving his Assent to their Acts of pretended Legislation:

For quartering large bodies of armed troops among us:

For protecting them, by a mock Trial from punishment for any Murders which they should commit on the Inhabitants of these States:

For cutting off our Trade with all parts of the world:

For imposing Taxes on us without our Consent:

For depriving us in many cases, of the benefit of Trial by Jury:

For transporting us beyond Seas to be tried for pretended offences:

For abolishing the free System of English Laws in a neighbouring Province, establishing therein an Arbitrary government, and enlarging its Boundaries so as to render it at once an example and fit instrument for introducing the same absolute rule into these Colonies:

For taking away our Charters, abolishing our most valuable Laws and altering fundamentally the Forms of our Governments:

For suspending our own Legislatures, and declaring themselves invested with power to legislate for us in all cases whatsoever.

He has abdicated Government here, by declaring us out of his Protection and waging War against us.

He has plundered our seas, ravaged our coasts, burnt our towns, and destroyed the lives of our people.

He is at this time transporting large Armies of foreign Mercenaries to compleat the works of death, desolation, and tyranny, already begun with circumstances of Cruelty & Perfidy scarcely paralleled in the most barbarous ages, and totally unworthy the Head of a civilized nation.

He has constrained our fellow Citizens taken Captive on the high Seas to bear Arms against their Country, to become the executioners of their friends and Brethren, or to fall themselves by their Hands.

He has excited domestic insurrections amongst us, and has endeavoured to bring on the inhabitants of our frontiers, the merciless Indian Savages whose known rule of warfare, is an undistinguished destruction of all ages, sexes and conditions.

In every stage of these Oppressions We have Petitioned for Redress in the most humble terms: Our repeated Petitions have been answered only by repeated injury. A Prince, whose character is thus marked by every act which may define a Tyrant, is unfit to be the ruler of a free people.

Nor have We been wanting in attentions to our British brethren. We have warned them from time to time of attempts by their legislature to extend an unwarrantable jurisdiction over us. We have reminded them of the circumstances of our emigration and settlement here. We have appealed to their native justice and magnanimity, and we have conjured them by the ties of our common kindred to disavow these usurpations, which, would inevitably interrupt our connections and correspondence. They too have been deaf to the voice of justice and of consanguinity. We must, therefore, acquiesce in the necessity, which denounces our Separation, and hold them, as we hold the rest of mankind, Enemies in War, in Peace Friends.

We, therefore, the Representatives of the united States of America, in General Congress, Assembled, appealing to the Supreme Judge of the world for the rectitude of our intentions, do, in the Name, and by Authority of the good People of these Colonies, solemnly publish and declare, That these united Colonies are, and of Right ought to be Free and Independent States; that they are Absolved from all Allegiance to the British Crown, and that all political connection between them and the State of Great Britain, is and ought to be totally dissolved; and that as Free and Independent States, they have full Power to levy War, conclude Peace, contract Alliances, establish Commerce, and to do all other Acts and Things which Independent States may of right do. And for the support of this Declaration, with a firm reliance on the protection of divine Providence, we mutually pledge to each other our Lives, our Fortunes and our sacred Honor.

New Hampshire: Josiah Bartlett, William Whipple, Matthew Thornton
Massachusetts: Samuel Adams, John Adams, John Hancock, Robert Treat Paine, Elbridge Gerry
Rhode Island: Stephen Hopkins, William Ellery
Connecticut: Roger Sherman, Samuel Huntington, William Williams, Oliver Wolcott
New York: William Floyd, Philip Livingston, Francis Lewis, Lewis Morris
New Jersey: Richard Stockton, John Witherspoon, Francis Hopkinson, John Hart, Abraham Clark
Pennsylvania: Robert Morris, Benjamin Rush, Benjamin Franklin, John Morton, George Clymer, James Smith, George Taylor, James Wilson, George Ross
Delaware: George Read, Caesar Rodney, Thomas McKean
Maryland: Samuel Chase, William Paca, Thomas Stone, Charles Carroll of Carrollton
Virginia: George Wythe, Richard Henry Lee, Thomas Jefferson, Benjamin Harrison, Thomas Nelson Jr., Francis Lightfoot Lee, Carter Braxton
North Carolina: William Hooper, Joseph Hewes, John Penn
South Carolina: Edward Rutledge, Thomas Heyward Jr., Thomas Lynch Jr., Arthur Middleton
Georgia: Button Gwinnett, Lyman Hall, George Walton


LeetCode - Algorithms - 149. Max Points on a Line

Problem

149. Max Points on a Line

Java

1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

class Solution {
public int maxPoints(int[][] points) {
int n = 0;
for (int i = 0; i < points.length; i++) {
int m = maxCollinearPoints(points, i);
if (m > n)
n = m;
}
return n;
}

private int maxCollinearPoints(int[][] points, int idx) {
Map<BigDecimal, Integer> map = new HashMap<BigDecimal, Integer>();
int x0 = points[idx][0];
int y0 = points[idx][1];
int x = 0, y = 0;
int duplicate = 1;
int vertical = 0;
for (int i = 0; i < points.length; i++) {
if (i != idx) {
x = points[i][0];
y = points[i][1];
if (x == x0) {
if (y == y0) {
duplicate++;
}
else {
vertical++;
}
} else {
BigDecimal deltaY = BigDecimal.valueOf(y - y0);
BigDecimal deltaX = BigDecimal.valueOf(x - x0);
BigDecimal slope = deltaY.divide(deltaX, 16, RoundingMode.FLOOR);
if (map.containsKey(slope)) {
map.put(slope, map.get(slope) + 1);
} else {
map.put(slope, 1);
}
}

}
}
int max = 0;
for (Integer num : map.values()) {
if (num + duplicate > max)
max = num + duplicate;
}
if ( (vertical + duplicate) > max )
max = vertical + duplicate;
return max;
}
}

Submission Detail

  • 41 / 41 test cases passed.
  • Runtime: 14 ms, faster than 72.08% of Java online submissions for Max Points on a Line.
  • Memory Usage: 39.6 MB, less than 41.21% of Java online submissions for Max Points on a Line.

programcreek

© https://www.programcreek.com/2014/04/leetcode-max-points-on-a-line-java/

This problem can be solve by counting points that have the same slope for each point. When counting, we need to be careful about the duplicate points and points on the vertical lines.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

class Solution {
public int maxPoints(int[][] points) {
HashMap<BigDecimal, Integer> result = new HashMap<BigDecimal, Integer>();
int max = 0;

for (int i = 0; i < points.length; i++) {
int duplicate = 1;
int vertical = 0;
for (int j = i + 1; j < points.length; j++) {
//handle duplicates and vertical
if (points[i][0] == points[j][0]) {
if (points[i][1] == points[j][1]) {
duplicate++;
} else {
vertical++;
}
} else {
BigDecimal slope =
points[j][1] == points[i][1] ? BigDecimal.valueOf(0.0) : BigDecimal.valueOf(1.0 * (points[j][1] - points[i][1])).divide(BigDecimal.valueOf(points[j][0] - points[i][0]), 16,
RoundingMode.FLOOR);
if (result.get(slope) != null) {
result.put(slope, result.get(slope) + 1);
} else {
result.put(slope, 1);
}
}
}

for (Integer count : result.values()) {
if (count + duplicate > max) {
max = count + duplicate;
}
}

max = Math.max(vertical + duplicate, max);
result.clear();
}

return max;
}
}

Submission Detail

  • 41 / 41 test cases passed.
  • Runtime: 25 ms, faster than 42.00% of Java online submissions for Max Points on a Line.
  • Memory Usage: 40.4 MB, less than 20.64% of Java online submissions for Max Points on a Line.