Gurpreet
BAN USERAssuming you have input from text file (say input.txt), below is a solution in Java.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class Solution {
public static void main(String[] args) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("input.txt"));
} catch (FileNotFoundException e) {
return;
}
try {
int tests = Integer.parseInt(reader.readLine());
for (int i = 0; i < tests; i++) {
testMatrix(reader);
}
} catch (IOException e) {
} finally {
try {
reader.close();
} catch (IOException e) {
}
}
}
private static void testMatrix(BufferedReader reader) throws IOException {
String[] tokens = reader.readLine().split(" ");
int n = Integer.parseInt(tokens[0]);
int m = Integer.parseInt(tokens[1]);
List<String> tmpList = new ArrayList<String>(n);
for (int i = 0; i < n; i++) {
tmpList.add(reader.readLine());
}
int columnRemoveIndex = 0;
Set<String> tmpSet = new HashSet<String>(n);
while (columnRemoveIndex < m) {
tmpSet.clear();
boolean canRemove = true;
for (String s : tmpList) {
StringBuilder tmpBuilder = new StringBuilder(s);
if (!tmpSet.add(tmpBuilder.deleteCharAt(columnRemoveIndex).toString())) {
canRemove = false;
break;
}
}
if (canRemove) {
System.out.println("Yes");
return;
}
columnRemoveIndex++;
}
System.out.println("No");
}
}
class Marks {
private int marks1, marks2, marks3, maxMarks;
public Marks(int a, int b, int c) {
marks1 = a;
marks2 = b;
marks3 = c;
maxMarks = getMax(marks1, marks2, marks3);
}
public int getMaxMarks() {
return maxMarks;
}
public boolean isPass() {
if ((marks1 + marks2 + marks3)/3 >= 40) {
return true;
}
return false;
}
private int getMax(int a, int b, int c) {
return getHigher(getHigher(a, b), c);
}
private int getHigher(int a, int b) {
if (a > b) {
return a;
}
return b;
}
}
import java.util.ArrayList;
import java.util.List;
class StudentList {
private List<Marks> allMarks;
public StudentList() {
allMarks = new ArrayList<Marks>();
}
public int totalStudents() {
return allMarks.size();
}
public int passCount() {
int count = 0;
for (Marks m : allMarks) {
if (m.isPass()) {
count++;
}
}
return count;
}
}
Yes. Remove 2nd column.
- Gurpreet September 03, 201400
11
01
10
Each row is unique after removing 2nd column.