Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

  • Advertisements

Author Archive

Determining The Complexity Of Algorithm (The Basic Part)

Posted by Pankil Patel on March 9, 2018

Time complexity – Very nice article

A Little Piece of Me

Hi buddy? many students or even your self talking about analysis algorithm often seen as a scary thing and I agree 100% cos I’m also not really sure about it since I believe analysis algorithm is a large thing and needs a high math knowledge to understand it, and the bad new is I hate talking about mathematics :-). However, through this article I’ll share you about the basics to analysis algorithm based on what I know about it with the hope at least it can help beginners who are trying to analysis algorithm. Finally, this is not as a perfection, there are lots of rooms for improvement or better articles about this stuff. And I state this is just a sharing! 🙂

View original post 1,582 more words

Advertisements

Posted in Uncategorized | Leave a Comment »

Coding Problem : Display Time

Posted by Pankil Patel on March 9, 2018

Problem:

By provided 6 different integer of (0 to 9)

Generate the time string which displays minimum time in 24 hours format.

For Example:

Input: 1, 8, 9, 2, 6, 4

Output: “16:28:49”

Solution :

package co.cc.enlightensoft.codility.self;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Solution_DisplayTime {

public String solution(int A, int B, int C, int D, int E, int F) {
 String result = "";

List data = new ArrayList<>(6);
 data.add(A);
 data.add(B);
 data.add(C);
 data.add(D);
 data.add(E);
 data.add(F);

Collections.sort(data);

// Special Cases
 if (data.get(0) == 0 && data.get(1) == 0 && data.get(2) == 0) {
 result = "0" + data.get(3) + ":0" + data.get(4) + ":0" + data.get(5);
 } else {
 result = finalString(data, -1, -1, -1);
 }

return result;
 }

private String finalString(List data, int lastH, int lastM, int lastS) {

// Hour Section
 int intHour = getHour(data, lastH);

String h = String.format("%02d", intHour);

String h1 = h.substring(0, 1);
 String h2 = h.substring(1, 2);

// Minute Section
 List minData = new ArrayList<>(data);

minData.remove(new Integer(h1));
 minData.remove(new Integer(h2));

int intMinute = getMinuteOrSec(minData, lastM);

String m = String.format("%02d", intMinute);
 String m1 = m.substring(0, 1);
 String m2 = m.substring(1, 2);

// Second Section
 List secData = new ArrayList<>(minData);
 secData.remove(new Integer(m1));
 secData.remove(new Integer(m2));

int intSec = getMinuteOrSec(secData, lastS);

// Recursive Conditions
 if (intSec >= 60) {
 return finalString(data, intHour - 1, intMinute, -1);
 }
 if (intMinute >= 60 && intHour > 23) {
 return "NOT POSSIBLE";
 }
 if (intMinute >= 60) {
 return finalString(data, intHour, -1, intSec);
 }
 if (intHour >= 24) {
 return finalString(data, -1, intMinute, intSec);
 }

return String.format("%02d", intHour) + ":" + String.format("%02d", intMinute) + ":"
 + String.format("%02d", intSec);
 }

private int getMinuteOrSec(List data, int lstMin) {
 int minSec = 60;
 for (int i = 0; i < data.size(); i++) {
 int j = i + 1;
 for (; j < data.size(); j++) {
 String hour = data.get(i) + "" + data.get(j);
 int curr = Integer.parseInt(hour);
 if (curr <= 59 && curr < minSec && lstMin < curr) {
 minSec = curr;
 break;
 }
 }

}
 return minSec;
 }

private int getHour(List data, int lstH) {
 int intHour = 24;
 for (int i = 0; i < data.size(); i++) {
 int j = i + 1;
 for (; j < data.size(); j++) {
 String hour = data.get(i) + "" + data.get(j);
 int currHour = Integer.parseInt(hour);
 if (currHour <= 23 && currHour < intHour && lstH < currHour) {
 intHour = currHour;
 break;
 }
 }

}
 return intHour;
 }

}

JUnit :

package co.cc.enlightensoft.codility.self;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class JUMainTest_DisplayTime {

Solution_DisplayTime s = new Solution_DisplayTime();

@Test
 public void testCase1() {

assertEquals("Failed", "12:36:48", s.solution(1, 8, 3, 2, 6, 4));
 }

@Test
 public void testCase2() {
 assertEquals("Failed", "16:28:49", s.solution(1, 8, 9, 2, 6, 4));
 }

/*
 * @Test public void testCase3() {
 *
 * assertEquals("Failed", "00:02:46", s.solution(0, 0, 0, 2, 6, 4)); }
 */

@Test
 public void testCase4() {
 assertEquals("Failed", "02:04:06", s.solution(0, 0, 0, 2, 6, 4));
 }

@Test
 public void testCase5() {

assertEquals("Failed", "NOT POSSIBLE", s.solution(9, 5, 8, 7, 6, 4));
 }

@Test
 public void testCase6() {

assertEquals("Failed", "00:00:00", s.solution(0, 0, 0, 0, 0, 0));
 }

}

Posted in Core Java, JDK 8 | Tagged: , , , , , , , , , | Leave a Comment »

Coding Problem : Air plan Seat Allocation

Posted by Pankil Patel on March 9, 2018

Problem:

10 seats in a row: with bunch of 3 + 4 + 3
Allocate 3 member’s family in continues seat allocation
Seat can not be spitted into other bunch.

Solution :


package co.cc.enlightensoft.codility.self;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * 
 * 1A 3C 2B 40G 5A
 * 
*/
public class Solution_AirplanSeatAllocation {

public int solution(int N, String S) {
 int result = 0;

Map<Integer, List> allSeatMap = new HashMap<>();
 String[] splitted = null;
 if (S.trim().length() > 0) {

splitted = S.split(" ");
 Arrays.sort(splitted);
 }
 for (int rowCount = 1; rowCount <= N; rowCount++) {

List row = new ArrayList<>(3);

List c1 = new ArrayList<>(3);
 c1.add(0);
 c1.add(0);
 c1.add(0);

List c2 = new ArrayList<>(4);
 c2.add(0);
 c2.add(0);
 c2.add(0);
 c2.add(0);

List c3 = new ArrayList<>(3);
 c3.add(0);
 c3.add(0);
 c3.add(0);

row.add(c1);
 row.add(c2);
 row.add(c3);

allSeatMap.put(rowCount, row);
 if (S.trim().length() > 0) {
 for (int j = 0; j < splitted.length; j++) {
 String code = splitted[j];

String subC = code.substring(1);

int currRow = Integer.parseInt(code.substring(0, 1));
 if (currRow == rowCount) {

switch (subC) {
 case "A":
 allSeatMap.get(rowCount).get(0).set(0, 1);
 break;
 case "B":
 allSeatMap.get(rowCount).get(0).set(1, 1);
 break;
 case "C":
 allSeatMap.get(rowCount).get(0).set(2, 1);
 break;
 case "D":
 allSeatMap.get(rowCount).get(1).set(0, 1);
 break;
 case "E":
 allSeatMap.get(rowCount).get(1).set(1, 1);
 break;
 case "F":
 allSeatMap.get(rowCount).get(1).set(2, 1);
 break;
 case "G":
 allSeatMap.get(rowCount).get(1).set(3, 1);
 break;
 case "H":
 allSeatMap.get(rowCount).get(2).set(0, 1);
 break;
 case "J":
 allSeatMap.get(rowCount).get(2).set(1, 1);
 break;
 case "K":
 allSeatMap.get(rowCount).get(2).set(2, 1);
 break;
 }
 }
 }
 }

}

for (int rowCount = 1; rowCount <= N; rowCount++) {
 if (!allSeatMap.get(rowCount).get(0).contains(1)) {
 // System.out.println(rowCount + "C1");
 result++;
 }

if (!allSeatMap.get(rowCount).get(1).contains(1)) {
 // System.out.println(rowCount + "C2");
 result++;
 } else if (allSeatMap.get(rowCount).get(1).get(1) == 0 && allSeatMap.get(rowCount).get(1).get(2) == 0) {
 if (allSeatMap.get(rowCount).get(1).get(0) == 0 || allSeatMap.get(rowCount).get(1).get(3) == 0) {
 // System.out.println(rowCount + "c2");
 result++;
 }
 }

if (!allSeatMap.get(rowCount).get(2).contains(1)) {
 // System.out.println(rowCount + "C3");
 result++;
 }

}
 return result;
 }

public boolean solution1(int[] A) {
 boolean result = true;

return result;
 }
}

JUnit Test Cases:

package co.cc.enlightensoft.codility.self;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class JUMainTest_AirplanSeatAllocation {

Solution_AirplanSeatAllocation s = new Solution_AirplanSeatAllocation();

@Test
 public void testCase1() {

assertEquals("Failed", 4, s.solution(2, "1A 2F 1C"));
 }

@Test
 public void testCase2() {

assertEquals("Failed", 7, s.solution(4, "1A 2F 1C 4A 3D 4C 3C 2G 4K"));
 }

@Test
 public void testCase3() {

assertEquals("Failed", 10, s.solution(5, "1A 2F 1C 4A 3D 4C 3C 2G 4K"));
 }

@Test
 public void testCase4() {

assertEquals("Failed", 116, s.solution(40, "1A 3C 2B 40G 5A"));
 }

@Test
 public void testCase5() {

assertEquals("Failed", 120, s.solution(40, ""));
 }

@Test
 public void testCase6() {

assertEquals("Failed", 0, s.solution(0, "1A"));
 }

}

Posted in Core Java, JDK 8 | Tagged: , , , , , , , , , | Leave a Comment »

Collections & Array Conversion with JDK 8

Posted by Pankil Patel on March 8, 2018

<Integer> ArrayList to int[] Array :

ArrayList<Integer> input = new ArrayList<Integer>();

int[] intArray = input.stream().mapToInt(i -> i).toArray();

Will Work with JDK 8

int[] Array to <Integer> ArrayList :

int[] result = new int[] { 3, 4, 5, 1, 2 };

List<Integer> intArrayList = (List<Integer>) Arrays.stream(result).boxed().collect(Collectors.toList());

Will Work with JDK 8

int[] Array to HashSet<Integer>:

HashSet<Integer> intHashSet = (HashSet<Integer>) Arrays.stream(intArray).boxed().collect(Collectors.toSet());

Will Work with JDK 8

HashSet<Integer> to TreeSet<Integer> :

SortedSet<Integer> intSortedSet = new TreeSet<Integer>(intHashSet);

Will Work with JDK 5, JDK 6, JDK 7 & JDK 8

 

int[] Array to TreeSet<Integer> :

SortedSet<Integer> intTreeSet = new TreeSet<Integer>();
for (int j = 0; j < intArray.length; j++) {
intTreeSet.add(intArray[j]);
}

Will Work with JDK 5, JDK 6, JDK 7 & JDK 8

 

 

 

 

Gooooooooooooooooooood Luck………………..

Posted in JDK 8 | Tagged: , , , , , , , , , , , , | Leave a Comment »

How to check Tree size of all folder in windows?

Posted by Pankil Patel on March 6, 2018

TreeSizeFree is very nice software to do this.

From below link you can get it:
https://filehippo.com/download_treesize_free/
https://www.jam-software.com/treesize_free/

Posted in Windows | Tagged: , , , , , | Leave a Comment »

Some useful Unix / Linux Commands

Posted by Pankil Patel on February 28, 2018

Some useful Unix / Linux Commands

I will add more here in this reblogged

 

To verify all the size and detail of the system:
df -h
or
df -hT /home
or
Refer link for more detail: https://www.tecmint.com/how-to-check-disk-space-in-linux/

Pankil Patel's Blog

To verify all the running Java process:
ps -ef |grep java

Using root account : To Know the all process with their port usage:
sudo lsof -i -P -n | grep LISTEN

To list out all the files and directories under current folder:
ls -ltr

Find string / word / pattern into all files of current folder:
find . | xargs grep 57932
or
find . | xargs grep ‘57731c92-0e1a-4d87-864d-5ee7975f6ac2’

Split the file into many based on size:
split -l 1000000 /logs/crmadapter.log.2016-12-12

Change User/Account:
sudo su – svc_profilesimp_global

Change Directory:
cd /u01/app/svc_profilesimp_global/tomcat/

View original post

Posted in Únix / Linux | Tagged: , , , , , , , , , , , , , , , , , , , , | Leave a Comment »

Mule ESB eclipse plug-in

Posted by Pankil Patel on June 26, 2014

Very nice explanation on the Mule ESB plug-in for eclipse on below URL:

http://blogs.mulesoft.org/installing-mule-studio-3-4-via-update-site-or-eclipse-marketplace/comment-page-1/

Posted in Uncategorized | Tagged: , , , | Leave a Comment »

Read property value in Java file using sprng 3 annotation

Posted by Pankil Patel on May 6, 2013

Step 1: Add your property bean definition in applicationContext.xml:

<bean id=“myPropValue”     class=“org.springframework.beans.factory.config.PropertiesFactoryBean”>
               <property name=“location”value=“classpath:myPropertyFile.properties” />
</bean>
 

Step 2: Read Property by constructor injection of property bean into Spring service.:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 

@Service(“myService”)

public class MyServiceImpl implements MyService {

private Properties allValueProperties;

       @Autowired
       public MyServiceImpl (Properties myPropValue) {
              this.allValueProperties = myPropValue;
       }
       @Override
       public void springWebMethod() throws Exception {
                   String valueFromProperty = this.allValueProperties.getProperty(“enlighten.my.default.value.url”);
       }

}

Note: If you don’t want to inject property bean in to your each spring service bean where it is required, alternatively you can inject it into one common bean and create static map from it or create enum from that properties and use that static map or enum in your any class of your application.

Posted in Spring | Tagged: , , , , , , | Leave a Comment »

Maven error reading, error in opening zip file

Posted by Pankil Patel on January 15, 2013

error: error reading C:\Users\ppatel4\.m2\repository\org\apache\xalan\xalan\2.7.
1\xalan-2.7.1.jar; error in opening zip file

Step 1: Manually download xalan-2.7.1.jar

Step 2: Remove all files of: ~/.m2/repository/org/apache/xalan/xalan/2.7.1/

Step3: Copy the jar which is manually downloaded into the location: ~/.m2/repository/org/apache/xalan/xalan/2.7.1/

$ cp xalan-2.7.1.jar ~/.m2/repository/org/apache/xalan/xalan/2.7.1/

Its Done… Try to execute your mvn clean install command.

All the best…

Posted in Maven | Tagged: , , | Leave a Comment »

How to setup GMAIL account in BT-7722

Posted by Pankil Patel on January 2, 2013

VERY FIRST ENABLE POP3 FROM YOUR GMAIL ACCOUNT SETTINGS (thru internet browser). LOG IN TO YOUR GMAIL ACCOUNT > ON TOP RIGHT CLICK ON SETTINGS >THEN CLICK FORWARDING & POP3 > THEN ENABLE POP3 FOR ALL MAIL OR YOU CAN SELECT OTHER OPTION. BUT AT LEAST POP3 MUST BE ENABLED. THEN SAVE CHANGES.

POP3 Gmail Settings For Samsung B7722 / might be other samsung Cellphones also:

Go To > Menu (can be differ model to model basis but basic settings might be same for all samsung models > Messages

Click Settings > Email

Then Touch >Email Account / Email Setup Wizard

Then Touch > Add or Creat Account

Give name to your account name E.g Gmail or your Name or whatever you want

please note next menu orientation might be differ depending on model type, but you will find it)

SMTP / Outgoing Server : smtp.gmail.com

SMTP Port : 465

Secure Connection : SSL

Incoming Server type : POP3

POP3 / Incoming Server : pop.gmail.com

POP3 Port: 995

APOP Login : Tick

Secure Connection : SSL

Download Limit: 500

Retrieving Option: Choose Subject only (I have not tried for other option, you may try)

Keep On Server: Tick

My Email Address: type your gmail (email address)

Username /Password : your gmail ID / Password

POP before SMTP : Dont Tick

SMTP Auth: Tick

Same as POP3/IMAP4 : Tick

And Finally SAVE All Settings.

That’s it !!!, Now you can SEND & RECIEVE YOUR gmail messages on your samsung phones.

Best Of Luck……………………

Posted in Out Of The World | Leave a Comment »